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

javac generates class with invalid stack map

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 17
    • 17
    • tools
    • None
    • b31

        Following class compiled with --enable-preview:
        ---
        public class T {

            static void m(java.util.function.Consumer<Object> cons) {}

            public static void main(String[] args) {
                m(o -> {
                    if (o instanceof CharSequence chs) {
                        switch (chs) {
                            default -> {}
                        }
                    }
                });
            }
        }

        ---
        Fails to initialize due to invalid stack map:
        ---
        Error: Unable to initialize main class T
        Caused by: java.lang.VerifyError: Bad local variable type
        Exception Details:
          Location:
            T.lambda$main$0(Ljava/lang/Object;)V @12: aload_2
          Reason:
            Type top (current frame, locals[2]) is not assignable to reference type
          Current Frame:
            bci: @12
            flags: { }
            locals: { 'java/lang/Object', 'java/lang/CharSequence' }
            stack: { }
          Bytecode:
            0000000: 2ac1 0011 9900 242a c000 114c 2c59 b800
            0000010: 1357 4d03 3e2c 1dba 0019 0000 ab00 0000
            0000020: 0000 000c 0000 0000 b1
          Stackmap Table:
            append_frame(@21,Object[#17],Object[#17],Integer)
            chop_frame(@40,3)

              jlahoda Jan Lahoda
              asotona Adam Sotona
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: