From b21f3efcfda1a07eceb877487dc3bf666e38a6c3 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 30 May 2020 11:23:23 +0200 Subject: [PATCH] [java] UseProperClassLoader can not detect the case with method call on intermediate variable Fixes #2544 --- docs/pages/release_notes.md | 3 +++ .../main/resources/category/java/errorprone.xml | 2 +- .../errorprone/xml/UseProperClassLoader.xml | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index b8f8783555..22207771c8 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,6 +16,9 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* java-errorprone + * [#2544](https://github.com/pmd/pmd/issues/2544): \[java] UseProperClassLoader can not detect the case with method call on intermediate variable + ### API Changes ### External Contributions diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index ebd938006e..8033820e7f 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3532,7 +3532,7 @@ Thread.currentThread().getContextClassLoader() instead. - //PrimarySuffix[@Image='getClassLoader'] + //PrimarySuffix[@Image='getClassLoader'] | //PrimaryPrefix[ends-with(Name/@Image, '.getClassLoader')] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseProperClassLoader.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseProperClassLoader.xml index 4fa1d46e23..e6c8238078 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseProperClassLoader.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseProperClassLoader.xml @@ -20,6 +20,23 @@ public class Foo { + + + + False negatives (#2544) + 2 + 4,7 + c = o.getClass(); + ClassLoader cl2 = c.getClassLoader(); + } } ]]>