-
Bug
-
Resolution: Fixed
-
P4
-
13
-
b20
-
Verified
A DESCRIPTION OF THE PROBLEM :
Annotating a receiver type with an annotation whose target is PARAMETER compiles fine, but the annotation is not present in byte code.
It should fail because according to JLS 9.7.4:
"It is a compile-time error if an annotation of type T is syntactically a modifier for: [...] a receiver parameter, but T is not applicable to type contexts."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try compiling the code provided below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javac should fail because the `@Param` annotation is not valid on the receiver type.
ACTUAL -
javac compiles the code
---------- BEGIN SOURCE ----------
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
class ReceiverParamAnnotation {
@Retention(RUNTIME)
@Target({ElementType.TYPE_USE})
@interface TypeUse { }
@Retention(RUNTIME)
@Target({ElementType.PARAMETER})
@interface Param { }
public void test(@TypeUse @Param ReceiverParamAnnotation this) { }
}
---------- END SOURCE ----------
FREQUENCY : always
Annotating a receiver type with an annotation whose target is PARAMETER compiles fine, but the annotation is not present in byte code.
It should fail because according to JLS 9.7.4:
"It is a compile-time error if an annotation of type T is syntactically a modifier for: [...] a receiver parameter, but T is not applicable to type contexts."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try compiling the code provided below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javac should fail because the `@Param` annotation is not valid on the receiver type.
ACTUAL -
javac compiles the code
---------- BEGIN SOURCE ----------
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
class ReceiverParamAnnotation {
@Retention(RUNTIME)
@Target({ElementType.TYPE_USE})
@interface TypeUse { }
@Retention(RUNTIME)
@Target({ElementType.PARAMETER})
@interface Param { }
public void test(@TypeUse @Param ReceiverParamAnnotation this) { }
}
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-8261197 Inconsistent handling of declaration annotations on receiver parameters
- Closed