Menu

#76 undetected uninitialized variable

closed-wont-fix
5
2014-08-17
2005-01-20
No

The Janino compiler doesn't detect uninitialized
variables and happily generates code for them, which
causes verify errors on classload. Simple example:

public class Bug
{
public static void main(String [] args)
{
java.lang.String s;
if (args.length > 2) {
s = "hello, world";
} else {
}
System.out.println(s);
}
}

Here's the output from janino-2.2.0:

Exception in thread "main" java.lang.VerifyError:
(class: Bug, method: main signature:
([Ljava/lang/String;)V) Accessing value from
uninitialized register 1
at java.lang.Class.getDeclaredMethods0(Native
Method)
at
java.lang.Class.privateGetDeclaredMethods(Class.java:1647)
at java.lang.Class.getMethod0(Class.java:1893)
at java.lang.Class.getMethod(Class.java:976)
at
org.codehaus.janino.JavaSourceClassLoader.main(Unknown
Source)

Discussion

  • Arno Unkrig

    Arno Unkrig - 2005-02-19

    Logged In: YES
    user_id=865893

    JANINO does not check "definite assignment" (JLS2 16).

    Checking of definite assignment is difficult to implement,
    which is why I leave it to the JVM ;-) JANINO is intended
    for "embedded" applications and is NOT a reference
    implementation of a Java compiler.

    I'll document JANINO's behavior in the "limitations" section
    in the JAVADOC of "Parser".

     
  • Arno Unkrig

    Arno Unkrig - 2005-02-19
    • status: open --> closed-wont-fix
     

Log in to post a comment.

MongoDB Logo MongoDB