Class CheckRelaxingNullnessAnnotation

java.lang.Object
org.objectweb.asm.ClassVisitor
org.objectweb.asm.tree.ClassNode
edu.umd.cs.findbugs.asm.ClassNodeDetector
edu.umd.cs.findbugs.detect.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.
  • Constructor Details

    • CheckRelaxingNullnessAnnotation

      public CheckRelaxingNullnessAnnotation(BugReporter bugReporter)
  • Method Details

    • visitMethod

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

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

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

      static Map<Integer, NullnessAnnotation> getNonnullOrNullableParams(@Nullable 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 Map<Integer, NullnessAnnotation> getNonnullOrNullableParamsFromTypeAnnotations(@Nullable 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
    • getNullness

      static @Nullable NullnessAnnotation getNullness(@SlashedClassName String annotationDesc)
    • containsNullness

      static boolean containsNullness(Collection<AnnotationValue> annotations, NullnessAnnotation nullness)
    • compatibleParameters

      static boolean compatibleParameters(String signature, String superSignature)
    • areRelated

      static boolean areRelated(String sig, String superSig)