Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3795

Consistently support NullNess annotations from meta-annotation in rules

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Rules, Symbolic Execution
    • Labels:
      None

      Description

      In SONARJAVA-3536, we made sure to consistently support the same set of annotations in all rules. Still, the behavior is inconsistent with meta-annotations.

      For example, RSPEC-4454 is correctly supporting when the Nonnull annotation is coming from a meta-annotation:

        public boolean equals(@MyAnnotation Object obj) { // Noncompliant: ""equals" method parameters should not be marked "@Nonnull"". *correct*!
          return true;
        }
      
        // Meta annotation
        @javax.annotation.Nonnull
        public @interface MyAnnotation
        {
        }
      

      Hovewer, meta-annotations are not supported in similar situations, for RSPEC-2637 for example:

        @javax.annotation.Nonnull
        String sDirectlyAnnotated = "abc";
      
        @MyAnnotation
        String sMetaAnnotated = "abc";
      
        void f() {
          sDirectlyAnnotated = null; // Noncompliant: "Nonnull set to null"  *correct*
          sMetaAnnotated = null; // Compliant, *FN*
        }
      
        // Meta annotation
        @javax.annotation.Nonnull
        public @interface MyAnnotation
        {
        }
      

      We should consistently support when the nullness annotation is coming from a meta-annotation.

      This will help to better support user-defined annotations relying on an existing one.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated: