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

Issue filter should also filter rules depending of the java warning suppressed

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.3
    • Component/s: Rules
    • Labels:
      None

      Description

      Issues are filtered by rule keys, meaning that if suppressWarnings() annotation does not explicitly mention a rule key (or all), issues won't be filtered.

      For instance, to remove S1874 issues, the following annotation is expected:

      @SuppressWarnings("java:S1874")
      MyDeprecatedType foo() {
        doSomething();
      }
      

      However, we should be able to also filter issues more smartly, by removing issues when an explicit compiler warning is used instead, if its overlap with the rule category:

      @SuppressWarnings("deprecation")
      MyDeprecatedType foo() { // should discard S1874 issue
        doSomething();
      }
      

      The supported warnings depend of the jvm/jdk constructor, but according to javac (javac -X, run on Ubuntu with Oracle JDK 11.0.3, javac documentation), the supported warnings are:

      Compiler warning Description Rule Candidate
      all to suppress all warnings any rule
      already covered by the filter
      auxiliaryclass to suppress warnings on auxiliary classes (you can specify more than one class in one .java file.
      The class which name matches .java file name will be the main class.
      All other classes in the file are "auxiliary" classes)
      none
      cast to suppress warnings relative to cast unnecessary and redundant casts RSPEC-1905
      classfile to suppress warnings relative to class file contents none
      deprecation to suppress warnings relative to deprecation (Suppresses only the ordinary deprecation warnings.) RSPEC-1874, (RSPEC-5738)
      dep-ann to suppress warnings relative to deprecated annotation RSPEC-1123
      divzero to suppress warnings relative to division by zero RSPEC-3518
      empty to suppress warnings relative to empty statements after if statements RSPEC-108, RSPEC-1116
      exports to suppress warnings relative to module exports. none
      fallthrough to suppress warnings relative to missing breaks in switch statements RSPEC-128
      finally to suppress warnings relative to finally block that don't return RSPEC-1143
      module to suppress warnings relative to module system related issues. none
      opens to suppress warnings relative to module opens. none
      options not related to java code itself, but javac command line options  
      overloads to supress warnings relative to method overloads none
      overrides to suppress warnings relative to method overrides RSPEC-1206
      path not related to java code itself, but javac command line path option.
      It warns about invalid path elements and nonexistent path directories on the command line
      (with regard to the class path, the source path, and other paths)
       
      processing to supress warnings relative to issues regarding annotation processing none
      rawtypes to suppress warnings relative to usage of raw types RSPEC-3740
      removal to suppress warnings relative to usagee of API that has been marked for removal. Suppresses only the removal warnings. RSPEC-5738
      requires-automatic to suppress warnings relative to usage of automatic modules in the requires clauses. none
      requires-transitive-automatic to suppress warnings relative to automatic modules in requires transitive. none
      serial to suppress warnings relative to missing serialVersionUID field for a serializable class RSPEC-2057
      already cover by the rule
      static to suppress warnings relative to use of statics RSPEC-2209
      try to suppress warnings relative to use of try blocks, including try-with-resources statements none
      unchecked to suppress warnings relative to unchecked operations none
      varargs to suppress warnings relative to unsafe usages of variable arguments (varargs) methods,
      in particular, those that contain non-reifiable arguments (type whose type information is not fully available at runtime)
      none
      preview to suppress warnings relative to usage of preview language features none

      There is also other warnings supported by various IDEs which may be covered. For instance with eclipse Oxygen: https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-suppress_warnings.htm

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              quentin.jaquier Quentin Jaquier
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: