Class CheckRelaxingNullnessAnnotation

  • All Implemented Interfaces:
    Detector2, Priorities

    public class CheckRelaxingNullnessAnnotation
    extends ClassNodeDetector
    Checks that overriding methods do not relax NonNull (made Nullable) on return values or Nullable (made NonNull) on parameters. The code accepts also old (deprecated) nullness annotations from edu.umd.cs.findbugs.annotations package.
    • Field Summary

      • Fields inherited from class org.objectweb.asm.tree.ClassNode

        access, attrs, fields, innerClasses, interfaces, invisibleAnnotations, invisibleTypeAnnotations, methods, module, name, nestHostClass, nestMembers, outerClass, outerMethod, outerMethodDesc, permittedSubclasses, recordComponents, signature, sourceDebug, sourceFile, superName, version, visibleAnnotations, visibleTypeAnnotations
      • Fields inherited from class org.objectweb.asm.ClassVisitor

        api, cv
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static boolean areRelated​(java.lang.String sig, java.lang.String superSig)  
      (package private) static boolean compatibleParameters​(java.lang.String signature, java.lang.String superSignature)  
      (package private) static boolean containsNullness​(java.util.Collection<AnnotationValue> annotations, NullnessAnnotation nullness)  
      (package private) static boolean containsRelaxedNonNull​(@Nullable java.util.List<org.objectweb.asm.tree.AnnotationNode> methodAnnotations)  
      (package private) static boolean containsRelaxedNonNullTypeUse​(@Nullable java.util.List<org.objectweb.asm.tree.TypeAnnotationNode> typeAnnotations)  
      (package private) static java.util.Map<java.lang.Integer,​NullnessAnnotation> getNonnullOrNullableParams​(@Nullable java.util.List<org.objectweb.asm.tree.AnnotationNode> @Nullable [] parameterAnnotations)
      Extracts nullness annotations from parameter declaration annotations.
      (package private) static java.util.Map<java.lang.Integer,​NullnessAnnotation> getNonnullOrNullableParamsFromTypeAnnotations​(@Nullable java.util.List<org.objectweb.asm.tree.TypeAnnotationNode> typeAnnotations)
      Extracts nullness annotations from method type annotations on formal parameters.
      (package private) static @Nullable NullnessAnnotation getNullness​(java.lang.String annotationDesc)  
      org.objectweb.asm.MethodVisitor visitMethod​(int methodAccess, java.lang.String methodName, java.lang.String desc, java.lang.String methodSignature, java.lang.String[] exceptions)  
      • Methods inherited from class org.objectweb.asm.tree.ClassNode

        accept, check, visit, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitModule, visitNestHost, visitNestMember, visitOuterClass, visitPermittedSubclass, visitRecordComponent, visitSource, visitTypeAnnotation
      • Methods inherited from class org.objectweb.asm.ClassVisitor

        getDelegate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CheckRelaxingNullnessAnnotation

        public CheckRelaxingNullnessAnnotation​(BugReporter bugReporter)
    • Method Detail

      • visitMethod

        public org.objectweb.asm.MethodVisitor visitMethod​(int methodAccess,
                                                           java.lang.String methodName,
                                                           java.lang.String desc,
                                                           java.lang.String methodSignature,
                                                           java.lang.String[] exceptions)
        Overrides:
        visitMethod in class org.objectweb.asm.tree.ClassNode
      • containsRelaxedNonNull

        static boolean containsRelaxedNonNull​(@Nullable java.util.List<org.objectweb.asm.tree.AnnotationNode> methodAnnotations)
      • containsRelaxedNonNullTypeUse

        static boolean containsRelaxedNonNullTypeUse​(@Nullable java.util.List<org.objectweb.asm.tree.TypeAnnotationNode> typeAnnotations)
      • getNonnullOrNullableParams

        static java.util.Map<java.lang.Integer,​NullnessAnnotation> getNonnullOrNullableParams​(@Nullable java.util.List<org.objectweb.asm.tree.AnnotationNode> @Nullable [] parameterAnnotations)
        Extracts nullness annotations from parameter declaration annotations.

        The map keys are the zero-based formal parameter indices, derived from each parameter's position in the parameter-annotation array. Annotations classified as NullnessAnnotation.CHECK_FOR_NULL are ignored.

        Parameters:
        parameterAnnotations - the parameter declaration annotations, or null
        Returns:
        a map from formal parameter indices to their nullness annotations, or an empty map if the parameter-annotation array is null or contains no relevant nullness annotations
      • getNonnullOrNullableParamsFromTypeAnnotations

        static java.util.Map<java.lang.Integer,​NullnessAnnotation> getNonnullOrNullableParamsFromTypeAnnotations​(@Nullable java.util.List<org.objectweb.asm.tree.TypeAnnotationNode> typeAnnotations)
        Extracts nullness annotations from method type annotations on formal parameters.

        Only annotations targeting TypeReference.METHOD_FORMAL_PARAMETER are considered. The map keys are the zero-based formal parameter indices encoded in the type references, rather than positions in the type-annotation list, which may contain annotations for other targets. Annotations classified as NullnessAnnotation.CHECK_FOR_NULL are ignored.

        Parameters:
        typeAnnotations - the method's visible or invisible type annotations, or null
        Returns:
        a map from formal parameter indices to their nullness annotations, or an empty map if the type-annotation list is null or contains no relevant nullness annotations
      • compatibleParameters

        static boolean compatibleParameters​(java.lang.String signature,
                                            java.lang.String superSignature)
      • areRelated

        static boolean areRelated​(java.lang.String sig,
                                  java.lang.String superSig)