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

FP on S1905 with method references and when using lambdas and default methods

    Details

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

      Description

      1) FP on lambdas and default methods:
      In the following code, the cast is required, because otherwise it would not be possible to use a lambda to declare the variable.

      interface A {
        default void foo() {  }
        default void bar() {  }
      
        interface B extends A {
          @Override
          void foo();
        }
      
        static void main() {
          A a = (B) () -> {  }; // FP S1905
        }
      }
      

      2) FP on method references when calling a default method of the functional interface. Ex:

      class A {
        static final Predicate<Object> IS_NULL_PREDICATE = ((Predicate<Object>) Objects::nonNull).negate(); // FP S1905 cast necessary
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                christophe.zurn Christophe Zurn
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: