Uploaded image for project: 'Product Roadmaps'
  1. Product Roadmaps
  2. MMF-664

Java: Add support for some annotations

    Details

    • Type: MMF
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Labels:

      Description

      Extra nullness annotations

      JSR-305 specifies a number of annotations to assist defect detection tools.
      The following annotations should be supported by SonarJava:

      • @javax.annotation.ParametersAreNonnullByDefault at the class or method level.
      • @javax.annotation.ParametersAreNullableByDefault at the class or method level.

      Similarly, the Eclipse IDE supports the following annotations:

      • @org.eclipse.jdt.annotation.NonNull
      • @org.eclipse.jdt.annotation.NonNullByDefault
      • @org.eclipse.jdt.annotation.Nullable

      IntelliJ also provides their custom annotations in org.jetbrains:annotations artefact:

      • @org.jetbrains.annotations.Nullable
      • @org.jetbrains.annotations.NotNull

      Meta annotations

      Spring 5 introduced the following ones, which are using @javax.annotation.Nullable and @javax.annotation.Nonnull from JSR-305 as meta-annotations:

      • @org.springframework.lang.Nullable
      • @org.springframework.lang.NonNullApi

      Instead of implemented explicit handling of these new eclipse annotations, a better approach could be to handle meta-annotations direction, which would allow us to also identify custom usages such as:

      package com.sonar.myProject.annotations;
      
      import javax.annotation.meta.TypeQualifierDefault;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      
      @javax.annotation.Nonnull
      @TypeQualifierDefault({ElementType.METHOD})
      @Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
      public @interface MethodsAreNonnullByDefault {
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jeanchristophe.collet Jean-Christophe Collet (Inactive)
                Reporter:
                jeanchristophe.collet Jean-Christophe Collet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: