Janino

Compiler can't find classes anymore (since 2.5.0)

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    2.5.0
  • Number of attachments :
    0

Description

This issue originates from "marcelll"'s message on NABBLE:

http://www.nabble.com/Compiler-can%27t-find-classes-anymore-%28since-2.5.0%29-tf2737647.html

Hello !

Since the introduction of version 2.5.0 the compiler can't find imported classes anymore.
So i switched back to 2.4.7 which is working correctly for me.
I think it has something to do with a restricted access mentioned in the 2.5.0 release.
I'm using the ClassBodyEvaluater (ClassBodyEvaluator.createFastClassBodyEvaluator...).

How can i make the needed classes visible again for the evaluator ?

Thanks in advance for any answer or code snippet !

Activity

Hide
Arno Unkrig added a comment -

Hi Marcelll,

marcelll wrote:
Hello ! Since the introduction of version 2.5.0 the compiler can't find imported classes anymore. So i switched back to 2.4.7 which is working correctly for me. I think it has something to do with a restricted access mentioned in the 2.5.0 release. I'm using the ClassBodyEvaluater (ClassBodyEvaluator.createFastClassBodyEvaluator...). How can i make the needed classes visible again for the evaluator ? Thanks in advance for any answer or code snippet !

I can't reproduce your problem. With JANINO 2.5.1, the following code executes OK:

((Runnable) ClassBodyEvaluator.createFastClassBodyEvaluator(
new Scanner(null, new StringReader(
"import java.util.*;\n" +
"public void run() {\n" + " new ArrayList();\n" + "}\n"
)),
Runnable.class,
null
)).run();

Am I missing something?

CU

Arno

Show
Arno Unkrig added a comment - Hi Marcelll, marcelll wrote: Hello ! Since the introduction of version 2.5.0 the compiler can't find imported classes anymore. So i switched back to 2.4.7 which is working correctly for me. I think it has something to do with a restricted access mentioned in the 2.5.0 release. I'm using the ClassBodyEvaluater (ClassBodyEvaluator.createFastClassBodyEvaluator...). How can i make the needed classes visible again for the evaluator ? Thanks in advance for any answer or code snippet ! I can't reproduce your problem. With JANINO 2.5.1, the following code executes OK: ((Runnable) ClassBodyEvaluator.createFastClassBodyEvaluator( new Scanner(null, new StringReader( "import java.util.*;\n" + "public void run() {\n" + " new ArrayList();\n" + "}\n" )), Runnable.class, null )).run(); Am I missing something? CU Arno
Hide
Arno Unkrig added a comment -

I used this with my customized class before:

Didn't work with 2.5.1:
Myclass myclass=(Myclass) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, "mysource", Myclass.class, null);

Worked again with 2.5.1:
Myclass myclass=(Myclass) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, "mysource", Myclass.class, Thread.currentThread().getContextClassLoader());

Apropos: i used nabble to post my messages to the mailing list (http://www.nabble.com/codehaus---janino-f11887.html).
Maybe you can link your website with this forum which makes it easier to post a message or read old information
for your excellent compiler.

With kind regards
Marcel

Show
Arno Unkrig added a comment - I used this with my customized class before: Didn't work with 2.5.1: Myclass myclass=(Myclass) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, "mysource", Myclass.class, null); Worked again with 2.5.1: Myclass myclass=(Myclass) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, "mysource", Myclass.class, Thread.currentThread().getContextClassLoader()); Apropos: i used nabble to post my messages to the mailing list (http://www.nabble.com/codehaus---janino-f11887.html). Maybe you can link your website with this forum which makes it easier to post a message or read old information for your excellent compiler. With kind regards Marcel
Hide
Arno Unkrig added a comment -

I successfully compiled again by adding the following classloader(Thread.currentThread().getContextClassLoader() )
.....ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new StringReader(script)), Class.class, Thread.currentThread().getContextClassLoader().
But i don't really know why it worked before without.
Maybe someone can give me a hint.

Show
Arno Unkrig added a comment - I successfully compiled again by adding the following classloader(Thread.currentThread().getContextClassLoader() ) .....ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new StringReader(script)), Class.class, Thread.currentThread().getContextClassLoader(). But i don't really know why it worked before without. Maybe someone can give me a hint.
Hide
Arno Unkrig added a comment -

I think I found the bug. Since 2.5.0

  • all the constructors of classes X that have an "optionalParentClassLoader" parameter
  • all methods "X.createFastX()" that have an "optionalParentClassLoader" parameter

(where "X" is "SimpleCompiler", "ClassBodyEvaluator", "ScriptEvaluator" or "ExpressionEvaluator"), and where that "optionalParentClassLoader" argument is NULL do not use the current thread's "context class loader" (as JAVADOC'ed), but the JVM's boot class loader (the one that finds only the classes on the boot class path).

I have fixed "SimpleCompiler.setParentClassLoader()" accordingly. Will go into version 2.5.2 (not scheduled yet).

The workaround is, as you found out, to pass "Thread.currentThread().getContextClassLoader()" instead
of NULL.

Show
Arno Unkrig added a comment - I think I found the bug. Since 2.5.0
  • all the constructors of classes X that have an "optionalParentClassLoader" parameter
  • all methods "X.createFastX()" that have an "optionalParentClassLoader" parameter
(where "X" is "SimpleCompiler", "ClassBodyEvaluator", "ScriptEvaluator" or "ExpressionEvaluator"), and where that "optionalParentClassLoader" argument is NULL do not use the current thread's "context class loader" (as JAVADOC'ed), but the JVM's boot class loader (the one that finds only the classes on the boot class path). I have fixed "SimpleCompiler.setParentClassLoader()" accordingly. Will go into version 2.5.2 (not scheduled yet). The workaround is, as you found out, to pass "Thread.currentThread().getContextClassLoader()" instead of NULL.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: