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

javac produces incorrect RuntimeInvisibleTypeAnnotations length attribute

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u65
    • Fix Version/s: 10
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      x86
    • OS:
      os_x

      Backports

        Description

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


        ADDITIONAL OS VERSION INFORMATION :
        Darwin ... 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        javac produces a length attribute for RuntimeInvisibleTypeAnnotations that can be larger than the total length of the method bytecode. This trips up ASM bytecode parsing (see stack below), which in turn prevents tools such as FindBugs or JaCoCo from running on affected bytecode.

        The Eclipse Compiler for Java does not appear to suffer from this problem.

        ASM parsing exception stack trace (produced with asm-debug-all-5.0.2.jar):
        Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 42
        at org.objectweb.asm.ClassReader.readLabel(ClassReader.java:2174)
        at org.objectweb.asm.ClassReader.readTypeAnnotations(ClassReader.java:1598)
        at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1184)
        at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1017)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:693)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile source code provided below.
        Check RuntimeInvisibleTypeAnnotations output provided by javap

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
              RuntimeInvisibleTypeAnnotations:
                0: #30(): LOCAL_VARIABLE, {start_pc=0, length=26, index=0}, location=[TYPE_ARGUMENT(0)]

        ACTUAL -
              RuntimeInvisibleTypeAnnotations:
                0: #30(): LOCAL_VARIABLE, {start_pc=0, length=42, index=0}, location=[TYPE_ARGUMENT(0)]


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.lang.annotation.ElementType;
        import java.lang.annotation.Target;
        import java.util.ArrayList;
        import java.util.Collection;

        public class ReproduceJavacBug {

        @Target(ElementType.TYPE_USE)
        public @interface Annotation {};

        public static void main(String [] args) {
        final Collection<@Annotation Object> list = new ArrayList<>();
        list.stream().forEach(r -> {
        int a = 0;
        System.out.println(a + "");
        list.size();
        throw new RuntimeException();
        });
        }

        }

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: