diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnnecessaryConversionRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConversionRule.java
similarity index 96%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnnecessaryConversionRule.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConversionRule.java
index d6f1f8f422..d8803369da 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnnecessaryConversionRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConversionRule.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd.lang.java.rule.bestpractices;
+package net.sourceforge.pmd.lang.java.rule.codestyle;
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
@@ -131,9 +131,9 @@ public class UnnecessaryConversionRule extends AbstractJavaRulechainRule {
boolean simpleConv = isReferenceSubtype(sourceType, conversionInput);
final String reason;
- if (simpleConv && conversionInput.unbox() == conversionOutput) {
+ if (simpleConv && conversionInput.unbox().equals(conversionOutput)) {
reason = "explicit unboxing";
- } else if (simpleConv && conversionInput.box() == conversionOutput) {
+ } else if (simpleConv && conversionInput.box().equals(conversionOutput)) {
reason = "explicit boxing";
} else if (sourceType.equals(conversionOutput)) {
reason = "boxing of boxed value";
diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml
index 8506686bf4..645c321a74 100644
--- a/pmd-java/src/main/resources/category/java/bestpractices.xml
+++ b/pmd-java/src/main/resources/category/java/bestpractices.xml
@@ -1358,37 +1358,6 @@ class Foo{
-
-
-
- Reports explicit conversions that may safely be removed, either because
- they would implicitly take place (eg widening a `byte` to an `int`), or
- because they're semantically a noop (eg unboxing a value to rebox it immediately).
-
- This handles widening conversion between primitives, boxing and unboxing
- conversions (which since Java 5 are inserted by the compiler implicitly),
- and unnecessary casts.
-
- 3
-
-
-
-
+
+
+ Reports explicit conversions that may safely be removed, either because
+ they would implicitly take place (eg widening a `byte` to an `int`), or
+ because they're semantically a noop (eg unboxing a value to rebox it immediately).
+
+ This handles widening conversion between primitives, boxing and unboxing
+ conversions (which since Java 5 are inserted by the compiler implicitly).
+ Unnecessary casts that command a conversion are reported by {% rule UnnecessaryCast %}
+ instead.
+
+ 3
+
+
+
+
Unnecessary (primitive -> primitive) casts
- 0
+ 1
+
+ Unnecessary explicit boxing
+