Janino

Setting attributes in catch() block causes NullPointerException in org.codehaus.janino.UnitCompiler.reclassifyName

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:
    Win XP; JDK 1.4??? and 1.5.0_04 tried; Janino 2.5.0
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

I updated from an old Janino version (from July 2005, don't know the exact version) to the 2.5.0 and ran into a really nasty issue with our dynamically generated code, which had worked without an issue since last August.

After 8 hours of stripping away all the funky stuff I had in mind for being a problem, it boiled down to ...:

This code works:

public String result="allow", email=null, anno=null, cnd=null, transactionID=null;

public String treeCode(String root)
{
try { return null; } catch (Exception treeEx) { treeEx.printStackTrace(); // result="allow"; }
return result;
}

and this doesn't:

public String treeCode(String root)
{
try { return null; } } catch (Exception treeEx) { treeEx.printStackTrace(); result="allow"; }
return result;
}

This is the exception thrown by the ClassBodyDemo; I'm attaching a zip file with both versions of the file. The working one only gets an error because main is not defined (java.lang.NoSuchMethodException: SC.main), but the other one dies as follows:

C:\projekte\fraudserver\janino\janino-2.5.0>java -classpath lib/janino.jar;classes org.codehaus.janino.samples.ClassBodyDemo @../janino-no-bug.java
Exception in thread "main" java.lang.NullPointerException
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.reclassify(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compileContext2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$31(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$6.visitAmbiguousName(UnitCompiler.java)
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compileContext(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$22(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$4.visitAssignment(UnitCompiler.java)
at org.codehaus.janino.Java$Assignment.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$4(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$2.visitExpressionStatement(UnitCompiler.java)
at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$3(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$2.visitBlock(UnitCompiler.java)
at org.codehaus.janino.Java$Block.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$8(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$2.visitTryStatement(UnitCompiler.java)
at org.codehaus.janino.Java$TryStatement.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$3(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$2.visitBlock(UnitCompiler.java)
at org.codehaus.janino.Java$Block.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$1.visitPackageMemberClassDeclaration(UnitCompiler.java)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java)
at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java)
at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java)
at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java)
at org.codehaus.janino.Cookable.cook(Cookable.java)
at org.codehaus.janino.Cookable.cook(Cookable.java)
at org.codehaus.janino.Cookable.cook(Cookable.java)
at org.codehaus.janino.ClassBodyEvaluator.<init>(ClassBodyEvaluator.java)
at org.codehaus.janino.samples.ClassBodyDemo.main(ClassBodyDemo.java)

Activity

Hide
Pelle Vehreschild added a comment -

Rolled back to 2.4.7, which did not work.

Then rolled back to 2.3.7, which works.

Show
Pelle Vehreschild added a comment - Rolled back to 2.4.7, which did not work. Then rolled back to 2.3.7, which works.
Hide
Arno Unkrig added a comment -

Oops...

Change method "UnitCompiler.reclassify(Location, Scope String)" from

while ((s instanceof Java.BlockStatement || s instanceof Java.CatchClause) && !(s instanceof Java.TypeBodyDeclaration)) s = s.getEnclosingScope();

to

while (
    (s instanceof Java.BlockStatement || s instanceof Java.CatchClause) // JANINO-70
    && !(s instanceof Java.TypeBodyDeclaration)
) s = s.getEnclosingScope();

Will be fixed in 2.5.1 (not scheduled yet).

Show
Arno Unkrig added a comment - Oops... Change method "UnitCompiler.reclassify(Location, Scope String)" from
while ((s instanceof Java.BlockStatement || s instanceof Java.CatchClause) && !(s instanceof Java.TypeBodyDeclaration)) s = s.getEnclosingScope();
to
while (
    (s instanceof Java.BlockStatement || s instanceof Java.CatchClause) // JANINO-70
    && !(s instanceof Java.TypeBodyDeclaration)
) s = s.getEnclosingScope();
Will be fixed in 2.5.1 (not scheduled yet).
Hide
Arno Unkrig added a comment -

Fixed in 2.5.1, published NOW.

Show
Arno Unkrig added a comment - Fixed in 2.5.1, published NOW.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: