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

Compiling generic class implementing Collection<T> throws java.lang.VerifyError.

XMLWordPrintable

    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      java -version
      openjdk version "1.8.0_171"
      OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
      OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

      uname -a
      Linux 4.13.0-45-generic #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      Info: Running GlassFish Version: GlassFish Server Open Source Edition 5.0 (build 25)

      Product Version: NetBeans IDE 8.2 (Build 201609300101)
      Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2
      Java: 1.8.0_171; OpenJDK 64-Bit Server VM 25.171-b11
      Runtime: OpenJDK Runtime Environment 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11
      System: Linux version 4.13.0-45-generic running on amd64; UTF-8; en_US (nb

      A DESCRIPTION OF THE PROBLEM :
      Compiling a generic class implementing Collection<T> as Part of a Maven Web Project in Netbeans 8.2 using GlassFish Server Open Source Edition 5.0 (build 25) throws the following error during build:

      test.example.testproject.CollectionTest@4aa298b7
      Exception in thread "main" java.lang.VerifyError: Illegal type at constant pool entry 6 in class test.example.testproject.X
      Exception Details:
        Location:
          test/example/testproject/X.spliterator()Ljava/util/Spliterator; @1: invokespecial
        Reason:
          Constant pool index 6 is invalid
        Bytecode:
          0x0000000: 2ab7 0006 b0


      REGRESSION : Last worked in version 8u171

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Install Netbeans 8.2 with Maven support
      - Install GlassFish Version: GlassFish Server Open Source Edition 5.0 (build 25)
      - Create a Maven Web Application Project using Glassfish 5 and Java EE Web 7
      - Insert the classes Main, X provided below
      - Run the project (Main class).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Project builds and runs without error.
      ACTUAL -
      Build throws the following error:

      test.example.testproject.CollectionTest@4aa298b7
      Exception in thread "main" java.lang.VerifyError: Illegal type at constant pool entry 6 in class test.example.testproject.X
      Exception Details:
        Location:
          test/example/testproject/X.spliterator()Ljava/util/Spliterator; @1: invokespecial
        Reason:
          Constant pool index 6 is invalid
        Bytecode:
          0x0000000: 2ab7 0006 b0

      ---------- BEGIN SOURCE ----------

      import java.util.Collection;
      import java.util.Iterator;
      import java.util.Spliterator;
      import java.util.function.Consumer;
      import java.util.function.Predicate;
      import java.util.stream.Stream;

      public class X<Y, Z extends Collection<Y>> implements Collection <Y> {
          
      public X(Z z, String s) {}
      public X(Class<Z> c, String s) {}

          @Override
          public int size() {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean isEmpty() {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean contains(Object o) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public Iterator<Y> iterator() {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public Object[] toArray() {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public <T> T[] toArray(T[] ts) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean add(Y e) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean remove(Object o) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean containsAll(Collection<?> clctn) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean addAll(Collection<? extends Y> clctn) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean removeAll(Collection<?> clctn) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean removeIf(Predicate<? super Y> prdct) {
              return Collection.super.removeIf(prdct); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public boolean retainAll(Collection<?> clctn) {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public void clear() {
              throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public Spliterator<Y> spliterator() {
              return Collection.super.spliterator(); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public Stream<Y> stream() {
              return Collection.super.stream(); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public Stream<Y> parallelStream() {
              return Collection.super.parallelStream(); //To change body of generated methods, choose Tools | Templates.
          }

          @Override
          public void forEach(Consumer<? super Y> cnsmr) {
              Collection.super.forEach(cnsmr); //To change body of generated methods, choose Tools | Templates.
          }

      }

      import test.example.testproject.X;
      import java.util.HashSet;

      public class Main {

          public static void main(String[] args) {
              X x = new X(new HashSet<String>(), "");
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      While this is not a useful workaround running the code as part of a Maven Java Application Project instead as part of a WebProject seems to avoid the issue.

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: