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

S1612 should not suggest method reference casting when the type is a primitive

    XMLWordPrintable

    Details

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

      Description

      Given the expression "abc".chars().mapToObj(i -> (char) i), S1612 raises an issue telling the user to replace the lambda with a method reference to char::cast. char::cast takes an Object as its argument causing i to be implicitly converted to Integer. Since casting Integer to char is invalid, this change turns a valid cast into an invalid one.

      To fix this problem, S1612 should not suggest using t::cast when t is a primitive type.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              quentin.jaquier Quentin Jaquier
              Reporter:
              sebastian.hungerecker Sebastian Hungerecker
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: