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

FP on S1943 with new methods from Java 11 having a Charset as parameter

    XMLWordPrintable

    Details

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

      Description

      Java 11 introduced some new methods which provide a Charset parameter in some of the methods flagged by RSPEC-1943.

      The rule should not raise issues for such invocations and should be updated.

      It is also possible that other cases are having new Charset parameters, which should then be covered and not raise issues.

      import java.io.File;
      import java.io.FileWriter;
      import java.io.IOException;
      import java.io.Writer;
      import java.nio.charset.StandardCharsets;
      
      class A {
        Writer foo(File file) throws IOException {
          return new FileWriter(file, StandardCharsets.UTF_8); // FP: this constructor is valid because it uses the proper charset
        }
      }
      

      Note: I was able to reproduce the issue on SonarQube, but not on my local SonarLint instance, due to SONARJAVA-3056 and the fact the the bytecode used to try to resolve the method invocation was not the java 11 from the project, but the java 8 from the IDE.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              michael.gumowski Michael Gumowski
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: