Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class.forName can't find classes in sbt-1.3.0-RC1 #4760

Closed
xerial opened this issue Jun 1, 2019 · 2 comments · Fixed by #4769
Closed

Class.forName can't find classes in sbt-1.3.0-RC1 #4760

xerial opened this issue Jun 1, 2019 · 2 comments · Fixed by #4769
Labels
area/classloader issues around layered ClassLoader
Milestone

Comments

@xerial
Copy link
Contributor

xerial commented Jun 1, 2019

steps

I'm still trying to find a reproduction, but basically, a problem happens when using Spark 2.4.x with Scala 2.11, sbt-1.3.0-RC1.

problem

  • Call a method in a dependent library that uses Class.forName("(class name)") -> causes java.lang.ClassNotFoundException
  • Call Class.forName("(class name)") works without any problem.

I guess some method (e.g., ClassLoader.getClassLoader(caller)) used in Class.forName has an issue in sbt-1.3.0-RC1's layered class loader:

   @CallerSensitive
    public static Class<?> forName(String className)
                throws ClassNotFoundException {
        Class<?> caller = Reflection.getCallerClass();
        return forName0(className, true, ClassLoader.getClassLoader(caller), caller);
    }

expectation

  • There has been no problem until sbt 1.2.8

notes

  • It seems a workaround is using Class.forName(name, true, Thread.currentThread().getContextClassLoader()) instead of Class.forName(name)
  • Spark is unrelated (fixed the description)

sbt version: 1.3.0-RC1

@xerial xerial changed the title Spark's class loader can't find some classes in sbt-1.3.0-RC1 Class.forName can't find classes in sbt-1.3.0-RC1 Jun 1, 2019
xerial added a commit to xerial/airframe that referenced this issue Jun 1, 2019
xerial added a commit to xerial/airframe that referenced this issue Jun 1, 2019
Use Class.forName with classloader
xerial added a commit to wvlet/airframe that referenced this issue Jun 1, 2019
@eed3si9n eed3si9n added the area/classloader issues around layered ClassLoader label Jun 3, 2019
@eed3si9n
Copy link
Member

eed3si9n commented Jun 3, 2019

@xerial Thanks the report.

It seems a workaround is using Class.forName(name, true, Thread.currentThread().getContextClassLoader()) instead of Class.forName(name)

I think @eatkins is working on a workaround along the same lines, but built-in to our layered ClassLoader so you won't have to do it.

@eatkins
Copy link
Contributor

eatkins commented Jun 3, 2019

See #4769.

@eed3si9n eed3si9n added this to the 1.3.0 milestone Jun 3, 2019
xerial added a commit to wvlet/airframe that referenced this issue Jun 13, 2019
xerial added a commit to wvlet/airframe that referenced this issue Jun 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/classloader issues around layered ClassLoader
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants