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 3cee0a6bd4..75a728a1d6 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
@@ -95,9 +95,9 @@ public class RedundantFieldInitializerRule extends AbstractJavaRule {
// remove the ending "f" or "F" for float
// values
s = s.substring(0, s.length() - 1);
- value = Float.valueOf(s);
+ value = Float.valueOf(s.replaceAll("_", ""));
} else if (literal.isDoubleLiteral()) {
- value = Double.valueOf(literal.getImage());
+ value = Double.valueOf(literal.getImage().replaceAll("_", ""));
} else if (literal.isCharLiteral()) {
value = (int) literal.getImage().charAt(1);
}
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 5a72358454..3722c2b586 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
@@ -1322,6 +1322,89 @@ public class SomeClass {
+
+
+
+ java7 numeric literals
+ 4
+ 8,21,31,47
+