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

RuntimeInvisibleTypeAnnotationsAttribute.annotations() API Index out of Bound error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • None
    • core-libs

      Test file javac/annotations/typeAnnotations/classfile/CombinationsTargetTest3.java use s ClassfileTestHelper.java to catch an RuntimeInvisibleTypeAnnotationsAttribute and count annotations number like this (within pattern match in switch):
      ```
                          case RuntimeInvisibleTypeAnnotationsAttribute invtAttr -> {
                              List <TypeAnnotation> tAnnots = invtAttr.annotations();
                              tinvisibles += tAnnots.size();
                              allt += tAnnots.size();
                          }
      ```
      When calling (RuntimeInvisibleTypeAnnotationsAttribute) invtAttr.annotations() API, there is an Index out of Bound error in the CodeImpl.getLabel.

      I attached the error screenshot. Test 25 was successfully compiled but fall into error.

      This is the source code snippet in CodeImpl.getLabel method (line 102).
      ```
          @Override
          public int labelToBci(Label label) {
              LabelImpl lab = (LabelImpl) label;
              if (lab.labelContext() != this)
                  throw new IllegalArgumentException(String.format("Illegal label reuse; context=%s, label=%s",
                                                                   this, lab.labelContext()));
              return lab.getBCI();
          }
      ```

      I checked the original test with old sun.tools.classfile API, and found the bci (which is 45) is correct. The size of LabelImpl[] (which is 37 according to the error message) generates the error.

            asotona Adam Sotona
            qxiao Qing Xiao (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: