From 7dcab3f189bb5b446c4ed97667907da2a24991c4 Mon Sep 17 00:00:00 2001 From: lukasgraef Date: Mon, 30 Sep 2024 20:48:20 +0200 Subject: [PATCH] Fix static analysis findings --- .../pmd/lang/java/rule/errorprone/CloseResourceRule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java index 440998cc8e..f7caef91b6 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java @@ -108,6 +108,7 @@ public class CloseResourceRule extends AbstractJavaRule { .desc("Detect if 'close' (or other closeTargets) is called outside of a finally-block").defaultValue(false).build(); private static final InvocationMatcher OBJECTS_NON_NULL = InvocationMatcher.parse("java.util.Objects#nonNull(_)"); + private static final InvocationMatcher FILESYSTEMS_GET_DEFAULT = InvocationMatcher.parse("java.nio.file.FileSystems#getDefault()"); private final Set types = new HashSet<>(); private final Set simpleTypes = new HashSet<>(); @@ -503,7 +504,7 @@ public class CloseResourceRule extends AbstractJavaRule { private boolean isDefaultFileSystem(ASTVariableId varId) { @Nullable ASTExpression initializer = varId.getInitializer(); - return initializer != null && InvocationMatcher.parse("java.nio.file.FileSystems#getDefault()").matchesCall(initializer); + return FILESYSTEMS_GET_DEFAULT.matchesCall(initializer); } private boolean isVariableSpecifiedInTryWithResource(ASTVariableId varId, ASTTryStatement tryWithResource) {