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

Error for a bad RuntimeVisibleParameterAnnotations attribute incorrectly refers to RuntimeInvisibleParameterAnnotations

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_162"
      Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      When attempting to compile a class that references another class that contains a malformed RuntimeVisibleParameterAnnotations attribute (i.e. proper structure, but incorrect number of parameters), the diagnostic message incorrectly claims that it is a malformed Runtime*In*visibleParameterAnnotations attribute. This is extremely confusing as it can cause a long search based off of a red herring error message; it should correctly state that it is RuntimeVisibleParameterAnnotations that is the problem.

      Obviously this error will only happen in extreme cases where things are already broken horribly, but the message being misleading simply makes an already annoying problem worse.

      In this case, "malformed" means that the num_parameters in the RuntimeVisibleParameterAnnotations attribute (JVMS §4.7.18) does not match the number of formal parameters of the method, but otherwise the structure of the attribute is correct.

      The cause of this is fairly simple, but since I haven't submitted the CLA I'm not sure how much I should detail. I think it'll suffice to say that there isn't a message written for RuntimeVisibleParameterAnnotations, and that ClassReader.attachParameterAnnotations is responsible for emitting the RuntimeInvisibleParameterAnnotations message.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile RVAAnnotation and RVACorrupt as found in the code below.
      2. Modify the RuntimeVisibleParameterAnnotations attribute in RVACorrupt.class by running `sed -i "s/\x07\x01\x00\x01\x00/\x09\x02\x00\x00\x00\x01\x00/" RVACorrupt.class` in the same directory. This adds another parameter at the start of the attribute, with 0 annotations. (I do not know of a way to generate such malformed code via javac, and there probably is not one).
      3. Attempt to compile RVATest. The error shown below will occur.
      4. Run `javap -v RVACorrupt` and observe that there are no RuntimeInvisibleParameterAnnotations attributes, only RuntimeVisibleParameterAnnotations.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An error message mentioning RuntimeVisibleParameterAnnotations
      ACTUAL -
      An error message mentioning Runtime*In*visibleParameterAnnotations

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      RVATest.java:2: error: cannot access RVACorrupt
              public RVACorrupt get() {
                     ^
        bad class file: .\RVACorrupt.class
          bad RuntimeInvisibleParameterAnnotations attribute: RVACorrupt(Object)
          Please remove or make sure it appears in the correct subdirectory of the classpath.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.annotation.*;

      @Target(ElementType.PARAMETER)
      @Retention(RetentionPolicy.RUNTIME)
      public @interface RVAAnnotation {
      }
      -------------
      public class RVACorrupt {
      public RVACorrupt(@RVAAnnotation Object something) { }
      }
      -------------
      public class RVATest {
      public RVACorrupt get() {
      return null;
      }
      }
      -------------
      Note that simply compiling these will not reproduce the issue; the class file must be mangled afterwards (see steps to reproduce)
      -------------
      javap output: https://gist.github.com/Pokechu22/29760e2c7f8d9cc34cbc1f7380de34a4
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      N/A (don't link against a corrupt class file -- if an error of this type is happening then the class is already corrupt and there is no simple workaround)

        Attachments

        1. RVAAnnotation.java
          0.1 kB
        2. RVACorrupt.java
          0.1 kB
        3. RVATest.java
          0.1 kB

          Activity

            People

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

              Dates

              • Created:
                Updated: