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

java.lang.VerifyError: Bad type on operand stack in runtime

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8, 9
    • Fix Version/s: 10
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

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


      ADDITIONAL OS VERSION INFORMATION :
      Linux unit-663 3.16.0-33-generic #44-Ubuntu SMP Thu Mar 12 12:19:35 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      public interface Main<T> {
          T create(T other);
       
          class Poly<T extends Main<T>> implements Main<Poly<T>> {
              static final Poly<?> INSTANCE = new Poly() {
              };
       
              public Poly<T> create(Poly<T> other) {
                  return new Poly<>();
              }
          }
       
          static void main(String[] args) {
              new Poly();
          }
      }


      Code compiles correctly, but fails in runtime:
      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          Main$Poly$1.create(Ljava/lang/Object;)Ljava/lang/Object; @2: invokespecial
        Reason:
          Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'Main$Poly'
        Current Frame:
          bci: @2
          flags: { }
          locals: { 'Main$Poly$1', 'java/lang/Object' }
          stack: { 'Main$Poly$1', 'java/lang/Object' }
        Bytecode:
          0x0000000: 2a2b b700 02b0

      at Main$Poly.<clinit>(Main.java:5)
      at Main.main(Main.java:14)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run this code
      public interface Main<T> {
          T create(T other);
       
          class Poly<T extends Main<T>> implements Main<Poly<T>> {
              static final Poly<?> INSTANCE = new Poly() {
              };
       
              public Poly<T> create(Poly<T> other) {
                  return new Poly<>();
              }
          }
       
          static void main(String[] args) {
              new Poly();
          }
      }



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      empty ouput, no fail
      ACTUAL -
      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          Main$Poly$1.create(Ljava/lang/Object;)Ljava/lang/Object; @2: invokespecial
        Reason:
          Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'Main$Poly'
        Current Frame:
          bci: @2
          flags: { }
          locals: { 'Main$Poly$1', 'java/lang/Object' }
          stack: { 'Main$Poly$1', 'java/lang/Object' }
        Bytecode:
          0x0000000: 2a2b b700 02b0

      at Main$Poly.<clinit>(Main.java:5)
      at Main.main(Main.java:14)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          Main$Poly$1.create(Ljava/lang/Object;)Ljava/lang/Object; @2: invokespecial
        Reason:
          Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'Main$Poly'
        Current Frame:
          bci: @2
          flags: { }
          locals: { 'Main$Poly$1', 'java/lang/Object' }
          stack: { 'Main$Poly$1', 'java/lang/Object' }
        Bytecode:
          0x0000000: 2a2b b700 02b0

      at Main$Poly.<clinit>(Main.java:5)
      at Main.main(Main.java:14)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public interface Main<T> {
          T create(T other);
       
          class Poly<T extends Main<T>> implements Main<Poly<T>> {
              static final Poly<?> INSTANCE = new Poly() {
              };
       
              public Poly<T> create(Poly<T> other) {
                  return new Poly<>();
              }
          }
       
          static void main(String[] args) {
              new Poly();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sadayapalam Srikanth Adayapalam
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: