A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3148 below:

[java] CloseResource false positive with Objects.nonNull · Issue #3148 · pmd/pmd · GitHub

Affects PMD Version:
6.30.0

Rule:

https://pmd.github.io/latest/pmd_rules_java_errorprone.html#closeresource

Description:

if using
if (Objects.nonNull(preparedStmt))
instead of
if (preparedStmt != null)
rule still fires a violation

Code Sample demonstrating the issue:

      PreparedStatement lPreparedStmt = null;
      try {
         lPreparedStmt = conn.prepareStatement(sqL);
         lPreparedStmt.execute();
      } catch (SQLException ex) {
         LOG.debug("lPreparedStmt.execute();loooooooooooooose" + ex);
      } finally {
         if (Objects.nonNull(lPreparedStmt)) {
            try {
               lPreparedStmt.close();
            } catch (SQLException pEx) {
               LOG.error("unrecoverable", pEx);
            }
         }
      }

Expected outcome:

false-positive

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
eclipse acanda plugin


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4