diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/RedundantFieldInitializerRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/RedundantFieldInitializerRule.java index 3fc599ffb6..f9d18882f5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/RedundantFieldInitializerRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/RedundantFieldInitializerRule.java @@ -100,7 +100,7 @@ public class RedundantFieldInitializerRule extends AbstractJavaRule { value = (int) literal.getImage().charAt(1); } - if (value.intValue() == 0) { + if (value.longValue() == 0) { addViolation(data, variableDeclarator); } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/RedundantFieldInitializer.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/RedundantFieldInitializer.xml index 268dbab4f0..ad2450bc61 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/RedundantFieldInitializer.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/RedundantFieldInitializer.xml @@ -1292,4 +1292,14 @@ public class Bar { } + + + #1418 RedundantFieldInitializer false positive with large long value + 0 + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index e034508139..f2060eded7 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -22,14 +22,16 @@ **Bugfixes:** * java-controversial/DefaultPackage: - * [#1410](https://sourceforge.net/p/pmd/bugs/1410/): DefaultPackage triggers on field annotated with @VisibleForTesting + * [#1410](https://sourceforge.net/p/pmd/bugs/1410/): DefaultPackage triggers on field annotated with @VisibleForTesting * java-design/CloseResource: - * [#1387](https://sourceforge.net/p/pmd/bugs/1387/): CloseResource has false positive for ResultSet + * [#1387](https://sourceforge.net/p/pmd/bugs/1387/): CloseResource has false positive for ResultSet +* java-optimizations/RedundantFieldInitializer + * [#1418](https://sourceforge.net/p/pmd/bugs/1418/): RedundantFieldInitializer false positive with large long value * java-strings/InsufficientStringBufferDeclaration: - * [#1409](https://sourceforge.net/p/pmd/bugs/1409/): NullPointerException in InsufficientStringBufferRule - * [#1413](https://sourceforge.net/p/pmd/bugs/1413/): False positive StringBuffer constructor with ?: int value + * [#1409](https://sourceforge.net/p/pmd/bugs/1409/): NullPointerException in InsufficientStringBufferRule + * [#1413](https://sourceforge.net/p/pmd/bugs/1413/): False positive StringBuffer constructor with ?: int value * java-unnecessary/UselessParentheses: - * [#1407](https://sourceforge.net/p/pmd/bugs/1407/): UselessParentheses "&" and "+" operator precedence + * [#1407](https://sourceforge.net/p/pmd/bugs/1407/): UselessParentheses "&" and "+" operator precedence **API Changes:**