-
Bug
-
Resolution: Fixed
-
P3
-
8u66, 9
-
b123
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8163708 | 8u121 | Shilpi Rastogi | P3 | Resolved | Fixed | b01 |
JDK-8159217 | 8u112 | Shilpi Rastogi | P3 | Resolved | Fixed | b01 |
JDK-8167834 | emb-8u121 | Shilpi Rastogi | P3 | Resolved | Fixed | b01 |
FULL PRODUCT VERSION :
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 3.2.0-97-generic #137-Ubuntu SMP Thu Dec 17 18:11:47 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Having static fields in an annotation type initialized by a lambda expression results in the annotations not being available in runtime.
This seems to happen in specific cases only. The following static fields work without problems:
Consumer<Integer> f2 = new B(); //with B a class implementing Consumer<Integer>
Consumer<Integer> f3 = C::eat; //with C::eat begin a static method
int f4 = 5;
Supplier<Integer> f5 = ()->5;
Consumer<Integer> f6 = new Consumer<Integer>() {
public void accept(Integer t) {}
};
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the unit test, execute.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The test succeeds. The annotation can be retrieved using reflection.
ACTUAL -
The test fails. the annotation is not available.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Consumer;
import junit.framework.TestCase;
@i
public class AnnotationWithStaticLambda extends TestCase {
public void testAnnotationWithStaticLambda() throws Exception {
assertEquals(1, myAnnotMinimal2.class.getAnnotations().length);
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface i {
Consumer<Integer> f1 = a -> {return;}; // -> 0
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using an instance of a class instead of a lambda works.
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 3.2.0-97-generic #137-Ubuntu SMP Thu Dec 17 18:11:47 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Having static fields in an annotation type initialized by a lambda expression results in the annotations not being available in runtime.
This seems to happen in specific cases only. The following static fields work without problems:
Consumer<Integer> f2 = new B(); //with B a class implementing Consumer<Integer>
Consumer<Integer> f3 = C::eat; //with C::eat begin a static method
int f4 = 5;
Supplier<Integer> f5 = ()->5;
Consumer<Integer> f6 = new Consumer<Integer>() {
public void accept(Integer t) {}
};
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the unit test, execute.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The test succeeds. The annotation can be retrieved using reflection.
ACTUAL -
The test fails. the annotation is not available.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Consumer;
import junit.framework.TestCase;
@i
public class AnnotationWithStaticLambda extends TestCase {
public void testAnnotationWithStaticLambda() throws Exception {
assertEquals(1, myAnnotMinimal2.class.getAnnotations().length);
}
}
@Retention(RetentionPolicy.RUNTIME)
@interface i {
Consumer<Integer> f1 = a -> {return;}; // -> 0
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using an instance of a class instead of a lambda works.
- backported by
-
JDK-8159217 Annotations with lambda expressions has parameter result in wrong behavior.
- Resolved
-
JDK-8163708 Annotations with lambda expressions has parameter result in wrong behavior.
- Resolved
-
JDK-8167834 Annotations with lambda expressions has parameter result in wrong behavior.
- Resolved
- relates to
-
JDK-8158510 Add test cases to validate Annotation
- Closed