S1604: FalsePositive if method has type parameters

Sonar rule S1604 raises an issue to convert an anonymous inner class to a lambda even if the method has type parameters.
But lambda expression cannot be used in this case.

See: https://stackoverflow.com/questions/22588518/lambda-expression-and-generic-method

Versions:

  • SonarQube: Version 6.7.2 (build 37468)
  • SonarJava: 5.11 (build 17289)

Hello,

Can you share a reproducer so we can be sure of the use case you are talking about?

Thanks

Sorry for the long delay:

import java.util.Arrays;
import java.util.List;

public class Repro {

	public static void main(String[] args) {
		List<String> list = Arrays.asList("a", "b", "c");
		sort(list, new MyComparable() {
			@Override
			public <T extends Comparable<T>> int compare(T obj1, T obj2) {
				return 0;
			}
		});
	}

	public static <T extends Comparable<T>> void sort(List<T> list, MyComparable comp) {
		//
	}
}

interface MyComparable {
	public <T extends Comparable<T>> int compare(T obj1, T obj2);
}

Hi,

Thanks a lot for the reproducer, I’ve created a ticket to fix this FP.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.