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

Incorrect class file created when passing lambda in inner class constructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8-pool, 9
    • tools
    • b93
    • x86_64
    • windows_7
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :
        Reproduced on all of these:

        java version "1.8.0_40"
        Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
        Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

        java version "1.8.0_25"
        Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
        Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

        java version "1.9.0-ea"
        Java(TM) SE Runtime Environment (build 1.9.0-ea-b57)
        Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b57, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7600]

        A DESCRIPTION OF THE PROBLEM :
        I compile the following class (CompilerBug.java)

        public class CompilerBug {
        int var = 0;

        public static void main(String[] args) {
        new CompilerBug().new Inner();
        }

        public class Inner {
        public Inner(Runnable r) {}

        public Inner() {
        this(() -> {
        var = 1;
        });
        }
        }
        }

        Compilation finishes without errors. However I see a VerifyError when running the compiled CompilerBug.class

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Create file CompilerBug.java (see "source code" section):

        2. Compile it:
        javac CompilerBug.java

        3. Run the compiled class:
        java CompilerBug

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Compilation error on step 2 like it's reported by ECJ:

        1. ERROR in C:\projects\Test\src\CompilerBug.java (at line 12)
        this(() -> {
        ^^^^^
        Cannot refer to 'this' nor 'super' while explicitly invoking a constructor

        ACTUAL -
        Compilation goes fine, but when compiled class is launched (step 3) the following error is displayed:

        Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
        Exception Details:
          Location:
            CompilerBug$Inner.<init>(LCompilerBug;)V @3: invokedynamic
          Reason:
            Type uninitializedThis (current frame, stack[2]) is not assignable to 'CompilerBug$Inner'
          Current Frame:
            bci: @3
            flags: { flagThisUninit }
            locals: { uninitializedThis, 'CompilerBug' }
            stack: { uninitializedThis, 'CompilerBug', uninitializedThis }
          Bytecode:
            0000000: 2a2b 2aba 0003 0000 b700 04b1

                at CompilerBug.main(CompilerBug.java:5)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public class CompilerBug {
        int var = 0;

        public static void main(String[] args) {
        new CompilerBug().new Inner();
        }

        public class Inner {
        public Inner(Runnable r) {}

        public Inner() {
        this(() -> {
        var = 1;
        });
        }
        }
        }

        ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

                sadayapalam Srikanth Adayapalam (Inactive)
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: