Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3345

S3518 (division by zero) should handle BigDecimal and BigInteger

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.7
    • Component/s: Rules, Symbolic Execution
    • Labels:
      None

      Description

      Current implementation of RSPEC-3518 does not support BigInteger and BigDecimal, while the divide() operation can still trigger a division by zero.

      Note that in order to handle this, we will need to track zeros and transmit them to the object created when instantiating a new BigDecimal/BigInteger (through constructors or valueOf() methods).

      Example:

        BigDecimal foo(BigDecimal v) {
          BigDecimal zero = BigDecimal.valueOf(0);
          return v.divide(zero);  // FN
        }
      
        BigInteger foo(BigInteger v) {
          BigInteger zero = BigInteger.valueOf(0);
          return v.divide(zero); // FN
        }
      
        int foo(int v) {
          int zero = 0;
          return v / zero;  // TP
        }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: