java.classpath

Do not assume that all classloaders in hierarchy implement URLClasspath

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Currently, java.classpath assumes that all classloaders in the hierarchy implement URLClasspath. This is not always true, nor is it always possible to achieve this.

Cursive recently switched to running Leiningen inside an isolated classloader tree using ShimDandy. When someone tries to work with a project with cider-nrepl in their profiles, they receive the following error:

java.lang.IllegalArgumentException: 
No implementation of method: :urls of protocol:
#'mranderson045.javaclasspath.v0v2v2.clojure.java.classpath/URLClasspath
found for class: com.intellij.util.lang.UrlClassLoader, compiling:(track_state.clj:57:8) 
No implementation of method: :urls of protocol:
#'mranderson045.javaclasspath.v0v2v2.clojure.java.classpath/URLClasspath
found for class: com.intellij.util.lang.UrlClassLoader

cider-nrepl uses java.classpath to introspect the classpath, and java.classpath walks the classloader hierarchy until it reaches the root classloader which is a com.intellij.util.lang.UrlClassLoader, which does not extend java.net.URLClassLoader. It is essential that this classloader not extend URLClassLoader because lein uses pomegranate to add jars to the classpath, and pomegranate will add those jars to the classpath using dynapath in the highest modifiable classloader it can find. It's important that that not be the root classloader since that would mean that lein plugins would be incorrectly loaded onto the classpath for different projects. Additionally, I cannot extend the URLClasspath protocol to the IntelliJ classloader because it's not available inside the shim.

I believe the solution is that java.classpath should check that the classloaders satisfy URLClasspath before calling urls on them.

Activity

Hide
Stuart Sierra added a comment -

I pushed a tentative fix to Git master as commit 39854b7f

Please test the SNAPSHOT release 0.2.3-20151024.163936-116, available from the Maven repository "https://oss.sonatype.org/content/groups/public/", and let me know if it resolves the problem.

Show
Stuart Sierra added a comment - I pushed a tentative fix to Git master as commit 39854b7f Please test the SNAPSHOT release 0.2.3-20151024.163936-116, available from the Maven repository "https://oss.sonatype.org/content/groups/public/", and let me know if it resolves the problem.
Hide
Colin Fleming added a comment -

Thanks. I actually managed to work around the problem on the Cursive side by sealing all URLClassLoaders using dynapath, but this is still a good change to make. I'll reproduce the original problem and make sure this fixes it.

Show
Colin Fleming added a comment - Thanks. I actually managed to work around the problem on the Cursive side by sealing all URLClassLoaders using dynapath, but this is still a good change to make. I'll reproduce the original problem and make sure this fixes it.
Hide
Stuart Sierra added a comment -

Fix included in 0.2.3 release.

Show
Stuart Sierra added a comment - Fix included in 0.2.3 release.
Hide
Stuart Sierra added a comment -

Fix was included in 0.2.3 release

Show
Stuart Sierra added a comment - Fix was included in 0.2.3 release

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: