Skip to content

Commit

Permalink
Fix Checkstyle annotation access checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hofer committed Jul 16, 2021
1 parent 910e5fc commit b36b3b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<property name="id" value="annotationAccess"/>
<metadata name="net.sf.eclipsecs.core.comment" value="Disallow calls to AnnotatedElement.get(Declared)Annotation(s)."/>
<property name="severity" value="error"/>
<property name="format" value="\b(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="format" value="(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either org.graalvm.util.GuardedAnnotationAccess or org.graalvm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="Checkstyle: allow direct annotation access"/>
<property name="onCommentFormat" value="Checkstyle: disallow direct annotation access"/>
<property name="checkFormat" value="annotationAccess"/>
<property name="idFormat" value="annotationAccess"/>
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable annotation access checks"/>
</module>

Expand Down
4 changes: 2 additions & 2 deletions substratevm/src/com.oracle.svm.core/.checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<property name="id" value="annotationAccess"/>
<metadata name="net.sf.eclipsecs.core.comment" value="Disallow calls to AnnotatedElement.get(Declared)Annotation(s)."/>
<property name="severity" value="error"/>
<property name="format" value="\b(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="format" value="(?&lt;!AnnotationAccess)\.(getAnnotation|getAnnotations|getDeclaredAnnotation|getDeclaredAnnotations|isAnnotationPresent)\b"/>
<property name="message" value="Direct calls to java.lang.reflect.AnnotatedElement.get(Declared)Annotation(s) are restricted. Use either org.graalvm.util.GuardedAnnotationAccess or org.graalvm.util.DirectAnnotationAccess methods. (Use &quot;// Checkstyle: allow direct annotation access... // Checkstyle: disallow direct annotation access&quot; to disable this check.)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="Checkstyle: allow direct annotation access"/>
<property name="onCommentFormat" value="Checkstyle: disallow direct annotation access"/>
<property name="checkFormat" value="annotationAccess"/>
<property name="idFormat" value="annotationAccess"/>
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable annotation access checks"/>
</module>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends Annotation> T getAnnotation(Class<T> annotationClass) {
Expand Down Expand Up @@ -1017,6 +1019,8 @@ public <T extends Annotation> T getDeclaredAnnotation(Class<T> 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b36b3b2

Please sign in to comment.