Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8323657

Compilation of snippet results in VerifyError at runtime with --release 9 (and above)

XMLWordPrintable

    • b07
    • generic
    • linux

        Filing for javac, but might as well a hotspot verifier issue. Not sure.

        The issue got originally filed via adoptium here:
        https://github.com/adoptium/adoptium-support/issues/991

        This snippet:

        public class Foo {
            public static void main(String[] args) {
            }
            private void unused() {
                boolean b;
                String test = ((((b = true) ? null : null) + "") + b);
            }
        }

        Compiles fine, but throws a VerifyError at runtime, unless --release 8 is being used when compiling the code:

        $bin/javac --release 8 Foo.java
        warning: [options] source value 8 is obsolete and will be removed in a future release
        warning: [options] target value 8 is obsolete and will be removed in a future release
        warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
        3 warnings
        $ bin/java Foo
        <nothing>

        Don't specify '--release 8' and we see the VerifyError:

        $ bin/javac Foo.java
        $ bin/java Foo
        Error: Unable to initialize main class Foo
        Caused by: java.lang.VerifyError: Bad local variable type
        Exception Details:
          Location:
            Foo.unused()Ljava/lang/String; @0: iload_1
          Reason:
            Type top (current frame, locals[1]) is not assignable to integer
          Current Frame:
            bci: @0
            flags: { }
            locals: { 'Foo' }
            stack: { }
          Bytecode:
            0000000: 1bba 0007 0000 4d2c b0

        Expected (runtime) behaviour:

        Works the same as when compiled with '--release 8', i.e. no VerifyError.

              jlahoda Jan Lahoda
              sgehwolf Severin Gehwolf
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: