JDK-8073658 : Invalid annotations in bridge methods
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u31
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-19
  • Updated: 2016-07-13
  • Resolved: 2016-07-13
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.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.8.0_31

A DESCRIPTION OF THE PROBLEM :
Annotation with target TYPE_USE seems to be copied to bridge methods. As bridge methods only delegate back to the overloaded method, these annotations are typically invalid. The reproducer shows that the type annotations specifies a PC range which is longer than the byte code of the method.
 
Probably type annotations shouldn't be copied to bridge methods. Please find reproducer, decompiled class file and analysis here:

https://gist.github.com/marchof/070ee2c2077bd095ba96


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Byte code processing tools like ASM file to parse files with invalid annotations.

REPRODUCIBILITY :
This bug can be reproduced always.

REPRODUCER:

The annotation with target TYPE_USE in the method doit(java.lang.Runnable) is copied
to the bridge method doit(java.lang.Object). While the bridge method only has 8
instructions, the range of the type annotation has a length of 15.

---------- BEGIN SOURCE ----------
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
 
public class ClassWithBridgeMethod<T extends Runnable> implements ParameterizedInterface<T> {
 
	@Override
	public void doit(final T t) {
		
		@TypeUseAnnotation
		Object x = null;
		
		// Some instructions just to widen the scope of annotation for x 
		System.out.println(x);
		System.out.println(x);
	}
 
}
 
interface ParameterizedInterface<T> {
	void doit(T arg);
}
 
@Target({ ElementType.TYPE_USE })
@Retention(RetentionPolicy.CLASS)
@interface TypeUseAnnotation {
}
---------- END SOURCE ----------


Comments
Same as JDK-8160928
13-07-2016

Annotation details are copying to bridge methods, because of the fix of JDK-6695379
09-02-2016

Attaching test case for future reference
01-02-2016

One thing to consider is to copy only the signature visible type annotations. Arguably those should be as applicable as the regular annotations we copy.
02-03-2015