-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7u80
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux XXX 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The subclass implements abstract method of abstract superclass and adds a method annotation to that method. At jdk 1.7.0_80 method.isAnnotationPresent returns TRUE for both superclass's and subclass's methods while at jdk 1.7.0_79 I've got TRUE for subclass's method and FALSE for superclass's method.
REGRESSION. Last worked in version 7u79
ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create custom method annotation with @Retention(RetentionPolicy.RUNTIME).
2. Create abstract superclass with abstract method.
3. Inherite superclass, implement method and add custom annotation for that method at subclass.
4. Get method array by calling Subclass.class.getDeclaredMethods().
5. Call method.isAnnotationPresent() for custom annotation.
6. Get different results for jdk 1.7.0_79 and jdk 1.7.0_80.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
jdk 1.7.0_79 and prior output:
subclass method is annotated - TRUE
superclass method is annotated - FALSE
ACTUAL -
jdk 1.7.0_80 output:
subclass method is annotated - TRUE
superclass method is annotated - TRUE
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Custom annotation class:
import java.lang.annotation.*;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
String value() default "";
}
Superclass:
public abstract class BaseClass {
public abstract Number getId();
}
Subclass:
public class InhClass extends BaseClass {
@Override
@MyAnnotation("id")
public Integer getId() {
return 0;
}
}
Main class to check method.isAnnotationPresent :
import java.lang.reflect.Method;
public final class Main {
public static void main(String[] args) {
try {
Method[] methods = InhClass.class.getDeclaredMethods();
for (Method method : methods) {
System.out.println(method.toString() + " annotated " + method.isAnnotationPresent(MyAnnotation.class));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux XXX 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The subclass implements abstract method of abstract superclass and adds a method annotation to that method. At jdk 1.7.0_80 method.isAnnotationPresent returns TRUE for both superclass's and subclass's methods while at jdk 1.7.0_79 I've got TRUE for subclass's method and FALSE for superclass's method.
REGRESSION. Last worked in version 7u79
ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create custom method annotation with @Retention(RetentionPolicy.RUNTIME).
2. Create abstract superclass with abstract method.
3. Inherite superclass, implement method and add custom annotation for that method at subclass.
4. Get method array by calling Subclass.class.getDeclaredMethods().
5. Call method.isAnnotationPresent() for custom annotation.
6. Get different results for jdk 1.7.0_79 and jdk 1.7.0_80.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
jdk 1.7.0_79 and prior output:
subclass method is annotated - TRUE
superclass method is annotated - FALSE
ACTUAL -
jdk 1.7.0_80 output:
subclass method is annotated - TRUE
superclass method is annotated - TRUE
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Custom annotation class:
import java.lang.annotation.*;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
String value() default "";
}
Superclass:
public abstract class BaseClass {
public abstract Number getId();
}
Subclass:
public class InhClass extends BaseClass {
@Override
@MyAnnotation("id")
public Integer getId() {
return 0;
}
}
Main class to check method.isAnnotationPresent :
import java.lang.reflect.Method;
public final class Main {
public static void main(String[] args) {
try {
Method[] methods = InhClass.class.getDeclaredMethods();
for (Method method : methods) {
System.out.println(method.toString() + " annotated " + method.isAnnotationPresent(MyAnnotation.class));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8029563 Method.getAnnotations() changed its return value in JDK 8.
- Closed
- relates to
-
JDK-6695379 Copy method annotations and parameter annotations to synthetic bridge methods
- Closed