Menu

#1263 java.lang.NumberFormatException in DumbMethods detector

3.0.0
closed-fixed
None
5
2014-04-29
2014-04-09
No

Analyze this program:

public class DumbMethodsNFE {
// Based on com.daffodilwoods.daffodildb.utils.field.FieldLiteral
public void crash(String msg) {
new java.math.BigDecimal(Double.POSITIVE_INFINITY);
if ("Infinite or NaN".equals(msg)) {}
}
}

Result:

Exception analyzing DumbMethodsNFE using detector edu.umd.cs.findbugs.detect.DumbMethods
java.lang.NumberFormatException: Infinite or NaN
At java.math.BigDecimal.<init>(Unknown Source)
At java.math.BigDecimal.<init>(Unknown Source)
At edu.umd.cs.findbugs.detect.DumbMethods.sawOpcode(DumbMethods.java:1033)
At edu.umd.cs.findbugs.visitclass.DismantleBytecode.visit(DismantleBytecode.java:835)
At edu.umd.cs.findbugs.detect.DumbMethods.visit(DumbMethods.java:1178)
...</init></init>

Discussion

  • Peter C. Dillinger

    This fixes the problem, by the way:

    diff --git a/findbugs/src/java/edu/umd/cs/findbugs/detect/DumbMethods.java b/findbugs/src/java/edu/umd/cs/findbugs/detect/DumbMethods.java
    index 69d2e56..e14902e 100644
    --- a/findbugs/src/java/edu/umd/cs/findbugs/detect/DumbMethods.java
    +++ b/findbugs/src/java/edu/umd/cs/findbugs/detect/DumbMethods.java
    @@ -1027,7 +1027,7 @@ public class DumbMethods extends OpcodeStackDetector {
                         && getNameConstantOperand().equals("<init>") && getSigConstantOperand().equals("(D)V")) {
                     OpcodeStack.Item top = stack.getStackItem(0);
                     Object value = top.getConstant();
    
    -                if (value instanceof Double) {
    +                if (value instanceof Double && !((Double)value).isInfinite() && !((Double)value).isNaN()) {
                         double arg = ((Double) value).doubleValue();
                         String dblString = Double.toString(arg);
                         String bigDecimalString = new BigDecimal(arg).toString();
    
     
  • Andrey Loskutov

    Andrey Loskutov - 2014-04-20
    • status: open --> closed-fixed
    • assigned_to: Andrey Loskutov
     
  • Peter C. Dillinger

    Commit 1103397 passes all my tests (> 10 MLoC Java, compiled with Java 7 and below + 16K classes from Java API compiled with Java 8)

     

Log in to post a comment.

Monday.com Logo