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

FP in S2175 when a primitive is auto-boxed into a subtype of Number.

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.8
    • Fix Version/s: 6.9
    • Component/s: Rules
    • Labels:

      Description

      S2175 raises false positives when a primitive is auto-boxed into a subtype of Number.

      void simpleList() {
        List<Number> numberList = new ArrayList<>();
        numberList.add(Integer.valueOf(1));
        numberList.contains(1); // Compliant, FP
        numberList.contains(Integer.valueOf(1)); // Compliant, true negative
      }
      
      void mapWithNumberAsKey(int number) {
        Map<Number, String> testMap = new HashMap<>();
      
        testMap.put(Integer.valueOf(1), "one");
        testMap.put(Integer.valueOf(2), "two");
      
        String s;
        if (testMap.containsKey(number)) { // Compliant, FP
          s = testMap.get(number); // Compliant, FP
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: