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

FP on squid:RedundantThrowsDeclarationCheck with try-with-resource and exception thrown by close() method

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.13
    • Fix Version/s: 5.14
    • Component/s: Rules
    • Labels:
      None

      Description

      In the following code, the exception potentially thrown by the close() method need to be caught, or rethrown by the encapsulating method. Moreover, we can not remove the thrown exception without causing a compilation failure.

      The implementation of rule RSPEC-1130 should cover cases where the close() method signature have been changed to throw another exception than IOException, and not raise issue.

      import java.text.ParseException;
      
      public class A {
      
        public void parseExceptionCloseable() throws ParseException { // FP squid:RedundantThrowsDeclarationCheck
          try (ParseExceptionCloseable closeable = new ParseExceptionCloseable()) {
            // some code
          }
        }
      
        static class ParseExceptionCloseable implements AutoCloseable {
      
          @Override
          public void close() throws ParseException {
            throw new ParseException("", 0);
          }
        }
      
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alban.auzeill Alban Auzeill
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: