From b36b3b26a73dae73fede67d9d52ae03aecc7dff3 Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Fri, 25 Jun 2021 17:38:10 +0200 Subject: [PATCH] Fix Checkstyle annotation access checks. --- .../src/com.oracle.graal.pointsto/.checkstyle_checks.xml | 4 ++-- substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml | 4 ++-- .../src/com/oracle/svm/core/hub/DynamicHub.java | 4 ++++ .../com/oracle/svm/core/hub/SunReflectTypeSubstitutions.java | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/.checkstyle_checks.xml b/substratevm/src/com.oracle.graal.pointsto/.checkstyle_checks.xml index c5fd56059bbe..f964ae135817 100644 --- a/substratevm/src/com.oracle.graal.pointsto/.checkstyle_checks.xml +++ b/substratevm/src/com.oracle.graal.pointsto/.checkstyle_checks.xml @@ -19,14 +19,14 @@ - + - + diff --git a/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml b/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml index 624094600a9c..96f9c786de8a 100644 --- a/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml +++ b/substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml @@ -20,14 +20,14 @@ - + - + diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index e5fac067d70f..9dc551fd1628 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -950,6 +950,8 @@ private static Object newInstanceReachableError(Object instance) { "` was removed by reachability analysis. Use `Feature.BeforeAnalysisAccess.registerForReflectiveInstantiation` to register the type for reflective instantiation."); } +// Checkstyle: allow direct annotation access (false positives) + @Substitute @Override public T getAnnotation(Class annotationClass) { @@ -1017,6 +1019,8 @@ public T getDeclaredAnnotation(Class annotationClass) return AnnotationsEncoding.decodeAnnotations(annotationsEncoding).getDeclaredAnnotation(annotationClass); } +// Checkstyle: disallow direct annotation access + /** * This class stores similar information as the non-public class java.lang.Class.ReflectionData. */ diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/SunReflectTypeSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/SunReflectTypeSubstitutions.java index 08c65da102b3..bb20911b5611 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/SunReflectTypeSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/SunReflectTypeSubstitutions.java @@ -33,6 +33,7 @@ import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; +import org.graalvm.util.GuardedAnnotationAccess; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; @@ -143,7 +144,7 @@ class TypeVariableAnnotationsComputer implements CustomFieldValueComputer { @Override public Object compute(MetaAccessProvider metaAccess, ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) { - return ((TypeVariableImpl) receiver).getAnnotations(); + return GuardedAnnotationAccess.getAnnotations((TypeVariableImpl) receiver); } }