History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JANINO-70
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Arno Unkrig
Reporter: Pelle Vehreschild
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Janino

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

Created: 20/Oct/06 10:15 AM   Updated: 06/Nov/06 04:14 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive issue.zip (0.6 kb)

Environment: Win XP; JDK 1.4??? and 1.5.0_04 tried; Janino 2.5.0

Testcase included: yes


 Description  « Hide
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)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Pelle Vehreschild - 20/Oct/06 11:00 AM
Rolled back to 2.4.7, which did not work.

Then rolled back to 2.3.7, which works.


Arno Unkrig - 25/Oct/06 04:32 AM
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).


Arno Unkrig - 06/Nov/06 04:14 PM
Fixed in 2.5.1, published NOW.