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

FP in S2275 when second argument of String.format is an array

    Details

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

      Description

      In S2275, we partially support when the argument is an array, but we still face issue in situation like:

      String.format("%d and %d", getArray()); // S2275: not enough arguments. FP
      
      Object[] getArray() {
        return new Object[]{1,2};
      }
      
      String.format("%d%d", IntStream.range(0, 2).mapToObj(Integer::valueOf).toArray()); // FP
      String.format("%d%d", IntStream.range(0, 2).mapToObj(Integer::valueOf).toArray(Object[]::new)); // FP
      

      To avoid false positive, if the argument has Array type and we can not retrieve the elements, we should not raise an issue.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: