JDK-8197558 : Error for a bad RuntimeVisibleParameterAnnotations attribute incorrectly refers to RuntimeInvisibleParameterAnnotations
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9,10
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2018-02-10
  • Updated: 2025-04-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
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)


Comments
Seems these steps of reproduction no longer apply after JDK-8334870. Need to try producing malformed RVAA instead and see the messages.
15-04-2025

This issue is reproducible on 8, 9 and latest version of 10 8u172 - Fail 9 GA - Fail 9.0.4 - Fail 10 ea b42 - Fail below is the result executed on 10 ea b42 == -sh-4.2$ /scratch/fairoz/JAVA/jdk10/jdk-10-ea+42/bin/javac RVAAnnotation.java RVACorrupt.java -sh-4.2$ sed -i "s/\x07\x01\x00\x01\x00/\x09\x02\x00\x00\x00\x01\x00/" RVACorrupt.class -sh-4.2$ /scratch/fairoz/JAVA/jdk10/jdk-10-ea+42/bin/javac RVATest.java 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. 1 error -sh-4.2$ /scratch/fairoz/JAVA/jdk-9.0.4/bin/javac RVATest.java
12-02-2018