FP S3546: Custom resources should be closed

  • Sonarqube (Data Center Edition v2025.4.3 (113915))

  • Java

  • A custom rule base on rule template S3546

Parameters:

closingMethod: java.io.InputStream#close
constructor: java.io.InputStream
factoryMethod: com.example.sonar.s3546.StorageFacade#download(com.example.sonar.s3546.DomainType,java.lang.String)

  • Though InputStream in try-with-resources, “Close the InputStream” was reported.

au-dtangtest.zip (416.7 KB)

Hi,

Welcome to the community and thanks for this report!

I suspect this rule was never updated for the “newfangled” try-with-resources syntax. I’m going to flag this for the language experts.

 
Ann

Thank you for reporting this issue! Yes, it looks like try-with-resources is not supported with this rule. I created a ticket to track this issue: JAVASE-163.