Skip to content

Commit 08008bd

Browse files
committed
do not store AnnotationExtractor image singleton in a static field
1 parent ce928b7 commit 08008bd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/AnnotationUtil.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@
5353
*/
5454
public final class AnnotationUtil {
5555

56+
/**
57+
* Lazily created singleton to be used when outside the scope of a Native Image build.
58+
*/
5659
@Platforms(Platform.HOSTED_ONLY.class)
5760
static class Lazy {
5861
static final AnnotatedObjectAccess instance;
5962
static {
60-
if (ImageSingletons.contains(AnnotationExtractor.class)) {
61-
instance = (AnnotatedObjectAccess) ImageSingletons.lookup(AnnotationExtractor.class);
62-
} else {
63-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, AnnotatedObjectAccess.class, false, "java.base", "sun.reflect.annotation");
64-
instance = new AnnotatedObjectAccess();
65-
}
63+
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, AnnotatedObjectAccess.class, false, "java.base", "sun.reflect.annotation");
64+
instance = new AnnotatedObjectAccess();
6665
}
6766
}
6867

6968
@Platforms(Platform.HOSTED_ONLY.class)
7069
private static AnnotatedObjectAccess instance() {
70+
if (ImageSingletons.contains(AnnotationExtractor.class)) {
71+
return (AnnotatedObjectAccess) ImageSingletons.lookup(AnnotationExtractor.class);
72+
}
73+
// Fall back to singleton when outside scope of a Native Image build.
7174
return Lazy.instance;
7275
}
7376

0 commit comments

Comments
 (0)