From 10f5aa8d699e40357cc57e2448bd4dc552067c22 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Sat, 11 Oct 2008 18:38:37 +0000 Subject: [PATCH] Fixed patch 2075906 - Add toString() to the rule UnnecessaryWrapperObjectCreation git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6591 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../xml/UnnecessaryWrapperObjectCreation.xml | 13 +++++++++++++ pmd/rulesets/optimizations.xml | 3 +++ .../UnnecessaryWrapperObjectCreation.java | 1 + 4 files changed, 18 insertions(+) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 05badf6282..95dba22bb8 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ Fixed bug 1481051 - false + UnusedNullCheckInEquals (and other false positives too) Fixed bug 1943204 - Ant task: path should be relative to Ant basedir Fixed bug 2139720 - Exception in PMD Rule Designer for inline comments in source +Fixed patch 2075906 - Add toString() to the rule UnnecessaryWrapperObjectCreation Fixed ClassCastException on generic method in BeanMembersShouldSerialize Fixed ClassCastException in symbol table code diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UnnecessaryWrapperObjectCreation.xml b/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UnnecessaryWrapperObjectCreation.xml index 1fb37b8b6d..e9a67257a4 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UnnecessaryWrapperObjectCreation.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/optimizations/xml/UnnecessaryWrapperObjectCreation.xml @@ -40,4 +40,17 @@ public class Bar { ]]> java 1.5 + + + 1 + + diff --git a/pmd/rulesets/optimizations.xml b/pmd/rulesets/optimizations.xml index 50bb70560a..886c5f87ca 100644 --- a/pmd/rulesets/optimizations.xml +++ b/pmd/rulesets/optimizations.xml @@ -307,6 +307,9 @@ public int convert(String s) { i2 = Integer.valueOf(i).intValue(); // this wastes an object i2 = i; // this is better + String s3 = Integer.valueOf(i2).toString(); // this wastes an object + s3 = Integer.toString(i2); // this is better + return i2; } ]]> diff --git a/pmd/src/net/sourceforge/pmd/rules/optimization/UnnecessaryWrapperObjectCreation.java b/pmd/src/net/sourceforge/pmd/rules/optimization/UnnecessaryWrapperObjectCreation.java index 82878bb304..d290866610 100644 --- a/pmd/src/net/sourceforge/pmd/rules/optimization/UnnecessaryWrapperObjectCreation.java +++ b/pmd/src/net/sourceforge/pmd/rules/optimization/UnnecessaryWrapperObjectCreation.java @@ -25,6 +25,7 @@ public class UnnecessaryWrapperObjectCreation extends AbstractRule { }); private static final Set suffixSet = CollectionUtil.asSet(new String[] { + "toString", "byteValue", "shortValue", "intValue",