I’m using a FileWriter in order to write some analysis information of my application in a text file. The rule S1943 raises an issue even if the FileWriter is created with a CharSet - value like this:
BufferedWriter bw = new BufferedWriter(new FileWriter(resourcedFile, StandardCharsets.UTF_8));
Thanks for the feedback! I realized with this that the rule squid:S1943 has yet to be updated to cover methods which would have been introduced with Java 11. I created the following ticket to fix it: SONARJAVA-3057
I encountered the same issue as described here. We want to enforce this rule for our codebase but we want to keep some usages of FileReader and FileWriter that are created with Charset. I don’t see the rule has been changed yet. Will there be a change anytime soon? Thanks.
according to the ticket SONARJAVA-3057, this should be fixed in Version 5.12, but I checked it now in our codebase and actually there is still an Issue raised, when using the FileWriter constructor with an encoding set. We are using version 6.3.2.22818 of the java plugin.
I didn’t noticed before, as our developers marked the code with //NOSONAR.
I had a look at this problem, and it is true that this rule still reports false positives when using FileWriter or FileReader in some context. Ticket created: SONARJAVA-3772.
However, the case initially reported works fine on my side.
If the examples described in the ticket do not match the false positives you are facing, could you provide us a code sample raising the issue? Providing the exact issue message would help as well.
Perfect, I confirm that the issue you are facing is related to the problem described in the ticket above. I added your example to the description to make sure we are correctly supporting it.
Thank you very much @tschindler for coming back to us with a clear description of the issue.