Hello,
I am using SonarLint plugin version 4.3.0.3495 with IntelliJ IDEA 2019.3.1 (Ultimate Edition).
For this Java code :
package io.sami.lambda;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class LambdaGenericDemo {
public static void main(String[] args) {
LambdaGeneric<Integer> integerLambdaGeneric = new LambdaGeneric<>();
integerLambdaGeneric.method2(55, 58);
}
}
class LambdaGeneric<T extends Comparable<T>> {
static final Logger LOGGER = LogManager.getLogger(LambdaGeneric.class);
private static final Marker SIMPLE_OUTPUT = MarkerManager.getMarker("SIMPLE");
private T method(GenericFuncInterface<T> funcInterface, T t1, T t2) {
return funcInterface.myGenericFunc(t1, t2);
}
public void method2(T t1, T t2) {
GenericFuncInterface<T> tGenericFuncInterface = (ta, tb) -> {
if (ta.compareTo(tb) < 0) {
return tb;
} else {
return ta;
}
};
GenericFuncInterface<T> tGenericFuncInterface2 = (ta, tb) -> ta.compareTo(tb) < 0 ? tb : ta;
GenericFuncInterface<T> tGenericFuncInterface3 = (ta, tb) -> switch(ta.compareTo(tb)) {
case 2, 3, 5 -> tb;
default -> ta;
};
T t = method(tGenericFuncInterface, t1, t2);
T tt = method(tGenericFuncInterface2, t1, t2);
T ttt = method(tGenericFuncInterface3, t1, t2);
LOGGER.info(SIMPLE_OUTPUT, t);
LOGGER.info(SIMPLE_OUTPUT, tt);
LOGGER.info(SIMPLE_OUTPUT, ttt);
}
}
@FunctionalInterface
interface GenericFuncInterface<T> {
T myGenericFunc(T t1, T t2);
}
I am getting this error inside SonarLint “Log” tab :
Analysing ‘LambdaGenericDemo.java’…
File won’t be refreshed because there were errors during analysis: /home/sami/IdeaProjects/JavaLambda/src/main/java/io/sami/lambda/LambdaGenericDemo.java
After getting this error, SonarLint will ignore this Java file. No more analysis is done.
I am using JDK 13.0.1