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

FP on S1604 when multiple methods have default implementation and same signatures

    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

      In the following code, the 2 methods of the A interface have default implementation, and same signature (minus method name). Consequently, the new anonymous class cannot be rewritten as lambda, because it would make it ambiguous: the lambda could match both methods.

      interface A {
        default void foo(){}
        default void bar(){}
      
        static void main() {
          A a = new A() { // FP S1604 : using a lambda make it ambigous. Can not be resolved to foo or bar
            @Override
            public void foo() {
              // wants to be a lambda
            }
          };
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              michael.gumowski Michael Gumowski
              Reporter:
              michael.gumowski Michael Gumowski
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: