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

VerifyError on valid compiled code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 8
    • 7u25
    • tools
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.7.0_25"
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Class below compiles but runs with VerifyError exception

      public class Test {
          public static interface C<T> {
              T compute();
          }

          public static <T> T test(C<T> c) {
              return c.compute();
          }

          public static class Wrapper<T> {
              public T value;
          }

          public static <T> T of(T t) {
              return t;
          }
          public static void main(String... args) {
              final Wrapper<String> w = new Wrapper<String>();
              test(new C<String>() {
                  public String compute() {
                      return w.value = of("test");
                  }
              });
          }
      }



      Exception in thread "main" java.lang.VerifyError: Bad return type in method Test$1.compute()Ljava/lang/String; at offset 13
      at Test.main(Test.java:20)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.VerifyError: Bad return type in method Test$1.compute()Ljava/lang/String; at offset 13
      at Test.main(Test.java:20)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {
          public static interface C<T> {
              T compute();
          }

          public static <T> T test(C<T> c) {
              return c.compute();
          }

          public static class Wrapper<T> {
              public T value;
          }

          public static <T> T of(T t) {
              return t;
          }
          public static void main(String... args) {
              final Wrapper<String> w = new Wrapper<String>();
              test(new C<String>() {
                  public String compute() {
                      return w.value = of("test");
                  }
              });
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Split
       return w.value = of("test");
      into 2 statement:
       w.value = of("test");
       return w.value;

            alundblad Andreas Lundblad (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: