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

FN in S2095 for sub-expressions in try-with-resources statements

    Details

    • Type: False Negative
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Rules
    • Labels:
      None

      Description

      Currently any expression that appears within the header of a try-with-resources statement is considered close, even if it is only a subexpression of a larger expression. So for example in the following statement the connection returned by `getConection` will be considered closed even though the `try` only closes the prepared statement, not the connection:

      try (var connection = dataSource.getConnection().prepareStatement("..."))
      

      This happens because we recursively visit all method calls in the header. Instead we should only look at the outer-most expressions and not visit subexpressions.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sebastian.hungerecker Sebastian Hungerecker
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: