Menu

#50 ClassCastException during compilation

All_releases
closed-fixed
5
2004-06-29
2004-06-28
No

I tried to compile the attached Foo.java (which
compiles fine with Sun's javac) with janinoc. Got back
the message "null". When called from my own code with
some similar generated code, here's the relevant
portion of the corresponding stack trace:

java.lang.ClassCastException
at net.janino.Java.invokeConstructor(Unknown Source)
at net.janino.Java.access$6400(Unknown Source)
at net.janino.Java$NewClassInstance.compileGet(Unknown
Source)
at net.janino.Java$Rvalue.compileGetValue(Unknown Source)
at net.janino.Java$FieldDeclarator.compile(Unknown Source)
at
net.janino.Java$ConstructorDeclarator.initializeInstanceVariablesAndInvokeInstanceInitializers(Unknown
Source)
at
net.janino.Java$ConstructorDeclarator.compilePreamble(Unknown
Source)
at net.janino.Java$FunctionDeclarator.compile(Unknown
Source)
at net.janino.Java$ClassDeclaration.compile(Unknown
Source)
at
net.janino.Java$AnonymousClassDeclaration.compile(Unknown
Source)
at
net.janino.Java$NewAnonymousClassInstance.compileGet(Unknown
Source)
at net.janino.Java$Rvalue.compileGetValue(Unknown Source)

Discussion

  • John V Sichi

    John V Sichi - 2004-06-28

    code to reproduce bug in isolation

     
  • John V Sichi

    John V Sichi - 2004-06-28

    Logged In: YES
    user_id=173374

    note: janino version 2.0.3; Sun java version 1.4.2_03-b02

     
  • John V Sichi

    John V Sichi - 2004-06-29

    Logged In: YES
    user_id=173374

    Here's a patch which fixes this bug:

    In src/net/janino/Java.java, change line 6415 from

    for (; s instanceof Statement; s =
    s.getEnclosingScope());
    to
    for (; !(s instanceof TypeBodyDeclaration);
    s = s.getEnclosingScope());

    This fixed my problem, but I haven't studied the code long
    enough to know whether it's a proper fix.

     
  • Arno Unkrig

    Arno Unkrig - 2004-06-29

    Logged In: YES
    user_id=865893

    The fix you proposed is perfect! Thank you.

    Will be released in version 2.0.4.

     
  • Arno Unkrig

    Arno Unkrig - 2004-06-29
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB