diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 6d1c0b8a12..4bb2d754ca 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -2,6 +2,7 @@ New rules: Basic-JSP ruleset: DuplicateJspImport Design ruleset: PreserveStackTrace + J2EE ruleset: UseProperClassLoader Implemented RFE 1462019 - Add JSPs to Ant Task Implemented RFE 1462020 - Add JSPs to Designer Fixed bug 1461426 InsufficientStringBufferDeclaration does not consider paths diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/j2ee/UseProperClassLoaderTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/j2ee/UseProperClassLoaderTest.java new file mode 100644 index 0000000000..7f09d00b03 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/j2ee/UseProperClassLoaderTest.java @@ -0,0 +1,34 @@ +package test.net.sourceforge.pmd.rules.j2ee; + +import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleSetNotFoundException; +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; +import test.net.sourceforge.pmd.testframework.TestDescriptor; + +public class UseProperClassLoaderTest extends SimpleAggregatorTst { + + private Rule rule; + + public void setUp() throws RuleSetNotFoundException { + rule = findRule("j2ee", "UseProperClassLoader"); + } + + public void testAll() { + runTests(new TestDescriptor[]{ + new TestDescriptor(TEST1, "failure case", 1, rule), + new TestDescriptor(TEST2, "correct way", 0, rule), + }); + } + + private static final String TEST1 = + "public class Foo {" + PMD.EOL + + " void bar() { ClassLoader cl = SomeClass.class.getClassLoader(); }" + PMD.EOL + + "}"; + + private static final String TEST2 = + "public class Foo {" + PMD.EOL + + " void bar() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); }" + PMD.EOL + + "}"; + +} diff --git a/pmd/rulesets/j2ee.xml b/pmd/rulesets/j2ee.xml new file mode 100644 index 0000000000..412e5c1680 --- /dev/null +++ b/pmd/rulesets/j2ee.xml @@ -0,0 +1,31 @@ + + + + + + + In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. + + + + + + + + 3 + + + + + + \ No newline at end of file diff --git a/pmd/rulesets/releases/37.xml b/pmd/rulesets/releases/37.xml index a62be41040..07fa64bbc9 100644 --- a/pmd/rulesets/releases/37.xml +++ b/pmd/rulesets/releases/37.xml @@ -8,6 +8,7 @@ This ruleset contains links to rules that are new in PMD v3.7 + diff --git a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java index 88081b71f3..4fc73f9716 100644 --- a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java +++ b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java @@ -52,6 +52,7 @@ public class SimpleRuleSetNameMapper { nameMap.put("design", "rulesets/design.xml"); nameMap.put("finalizers", "rulesets/finalizers.xml"); nameMap.put("imports", "rulesets/imports.xml"); + nameMap.put("j2ee", "rulesets/j2ee.xml"); nameMap.put("junit", "rulesets/junit.xml"); nameMap.put("javabeans", "rulesets/javabeans.xml"); nameMap.put("logging-java", "rulesets/logging-java.xml"); diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index 87484d89cb..36f5e5b0df 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -48,6 +48,7 @@
    +
  • Olaf Heimburger - wrote the UseProperClassLoader rule, code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree
  • Mohammad Farooq - Reported new JavaNCSS URL
  • Jeff Jensen - Reported missing XML schema references in documentation, wrote new XML schema, reported missing schema refs in example rulesets, suggested posting XML schema on PMD site, discussion of 'comments in catch block' feature, suggested description attribute in property element
  • Christopher Stach - bug report for VariableNamingConventions, bug report for CallSuperInConstructor, many bug reports for rules that didn't handle JDK 1.5 constructs
  • @@ -103,7 +104,6 @@
  • Eduard Naum - fixed JDK 1.3 runtime problems in Eclipse plugin
  • Jacques Lebourgeois - fix for UTF8 characters in Eclipse plugin
  • dvholten - suggestions for improving OverrideBothEqualsAndHashcode, formatting suggestions for HTML report, test cases for ConstructorCallsOverridableMethod, reported several NullAssignment bugs
  • -
  • Olaf Heimburger - code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree
  • Brian Duff - helped get Oracle JDeveloper plugin working
  • Sivakumar Mambakkam - bug report 1314086 for missing name in SimpleRuleSetNameMapper
  • Rodrigo Ruiz - bug report 1312723 for FieldDeclaration nodes inside interfaces, bug report 1312754 for pmd.bat option handling, bug report 1312720 (and code fix!) for DefaultPackage, bug report 1309235 for TooManyFields