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

ClassLoaderIClassLoader 's ClassNotFoundException handle mechanism enhancement #104

Closed
gr4ve opened this issue Sep 23, 2019 · 4 comments
Closed

Comments

@gr4ve
Copy link

gr4ve commented Sep 23, 2019

Class<?> clazz;
        try {
             clazz = Class.forName(Descriptor.toClassName(descriptor),
                           false, this.classLoader);
        } catch (ClassNotFoundException e) {
            if (e.getException() == null) {
                return null;
            } else
            {
                throw e;
            }
        }

in some osgi environment, the e.getException() will return a ClassNotFoundException too.
can we add an additional condition to handle above case?

Class<?> clazz;
        try {
             clazz = Class.forName(Descriptor.toClassName(descriptor),
                           false, this.classLoader);
        } catch (ClassNotFoundException e) {
            if (e.getException() == null || e.getException() instanceof ClassNotFoundException) {
                return null;
            } else
            {
                throw e;
            }
        }
@oontvoo
Copy link
Member

oontvoo commented Sep 23, 2019

Are you able to share the reproducible case?

I'm not sure it's a good idea to hide multiple upstream exceptions like this ... It could make debugging issues harder in the future

@aunkrig
Copy link
Member

aunkrig commented Sep 24, 2019

The aim is to distinguish between „Class does not exist“ and „exception when loading the class“, when the JRE maps both cases to ClassNotFoundException.

I‘ll change the code as requested (it is a good pattern to wrap exception X in another exception X in order to augment the message).

@aunkrig
Copy link
Member

aunkrig commented Sep 25, 2019

I fixed it:

            // Determine whether the class DOES NOT EXIST, or whether there were problems loading it. That's easier
            // said than done... the following seems to work:
            // (See also https://github.com/janino-compiler/janino/issues/104).
            {
                Throwable t = e.getCause();
                while (t instanceof ClassNotFoundException) t = t.getCause();
                if (t == null) return null;
            }

Please test!

aunkrig added a commit that referenced this issue Sep 25, 2019
@aunkrig aunkrig closed this as completed Dec 30, 2019
@agroh1
Copy link

agroh1 commented Apr 16, 2020

Thanks very much for this fix. I ran into this issue on a Spark cluster when using the old version and thought I would leave a stack trace so that people could find this issue more easily.

Caused by: org.codehaus.commons.compiler.CompileException: Line 11, Column 21: FunctionUtils
at org.codehaus.janino.UnitCompiler.findTypeByName(UnitCompiler.java:8473)
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java:8712)
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java:8381)
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java:8384)
at org.codehaus.janino.UnitCompiler.reclassify(UnitCompiler.java:8244)
at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:6768)
at org.codehaus.janino.UnitCompiler.access$14100(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$21$2$1.visitAmbiguousName(UnitCompiler.java:6410)
at org.codehaus.janino.UnitCompiler$21$2$1.visitAmbiguousName(UnitCompiler.java:6407)
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:4213)
at org.codehaus.janino.UnitCompiler$21$2.visitLvalue(UnitCompiler.java:6407)
at org.codehaus.janino.UnitCompiler$21$2.visitLvalue(UnitCompiler.java:6403)
at org.codehaus.janino.Java$Lvalue.accept(Java.java:4137)
at org.codehaus.janino.UnitCompiler$21.visitRvalue(UnitCompiler.java:6403)
at org.codehaus.janino.UnitCompiler$21.visitRvalue(UnitCompiler.java:6382)
at org.codehaus.janino.Java$Rvalue.accept(Java.java:4105)
at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:6382)
at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8939)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5060)
at org.codehaus.janino.UnitCompiler.access$9100(UnitCompiler.java:215)
at org.codehaus.janino.UnitCompiler$16.visitMethodInvocation(UnitCompiler.java:4421)
at org.codehaus.janino.UnitCompiler$16.visitMethodInvocation(UnitCompiler.java:4394)

Caused by: java.lang.ClassNotFoundException: FunctionUtils
at org.apache.spark.repl.ExecutorClassLoader.findClass(ExecutorClassLoader.scala:84)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:89)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:312)
at org.codehaus.janino.UnitCompiler.findTypeByName(UnitCompiler.java:8469)
... 127 more
Caused by: java.lang.ClassNotFoundException: FunctionUtils
at java.lang.ClassLoader.findClass(ClassLoader.java:524)
at org.apache.spark.util.ParentClassLoader.findClass(ParentClassLoader.scala:26)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at org.apache.spark.util.ParentClassLoader.loadClass(ParentClassLoader.scala:34)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at org.apache.spark.util.ParentClassLoader.loadClass(ParentClassLoader.scala:30)
at org.apache.spark.repl.ExecutorClassLoader.findClass(ExecutorClassLoader.scala:79)
... 134 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants