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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 10
    • 8, 9
    • tools
    • x86_64
    • linux

      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

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

              Created:
              Updated:
              Resolved: