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

SE based rules should not raise when exiting on exception with unknown type

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.7
    • Labels:
      None

      Description

      When reaching an EndOfExecutionPath, many rules explicitly do nothing when it exits on Runtime exceptions. If the exception is unknown, it either means that we failed to resolve the semantic or that it's an exception added by the engine to reflect that something bad happened. In both case, it makes sense to treat them as Runtime exception, excluding them the same way.

      Concerned rules:

      • S3546: CustomUnclosedResourcesCheck
      • S3516: InvariantReturnCheck
      • S2222: LocksNotUnlockedCheck
      • S2095: UnclosedResourcesCheck
      • S2755: XxeProcessingCheck

      Specific example for S2095, in the following snippet we raise FP, because called method creates exceptional yield with unknown exception type. S2095 should not raise issue on exit path with exception when exception type is unknown symbol.

       

      public class A {
      
        public class S2095FP {
          public static void main(String[] args) throws IOException {
            FileWriter fw = null;
            BufferedWriter output = null;
            try {
              fw = new FileWriter(args[0]);
              output = new BufferedWriter(fw); //S2095 unexpectedly raised here
            } finally {
              safeClose(fw);
              if (fw != null) {
                try {
                  fw.close();
                } finally {
                  if (output != null) {
                    output.close();
                  }
                }
              }
            }
      
          }
      
      
          public static void safeClose(Writer output){
            if (output != null) {
              try {
                output.close();
              } catch (IOException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                tibor.blenessy Tibor Blenessy
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: