Analyzing a Java file requires to provide its classpath to the Java analyzer (sonar.java.libraries). Since we are not passing rt.jar/jrt-fs.jar, the Java analyzer will fallback and use runtime JRE/JDK classes, which might not contains the same things.
I have created 2 sample projects to exhibit the problem:
- open the project in an IntelliJ having a Java 11 runtime
- assign a JDK 8 to the first module
- assign a JDK 13 to the second module
- enable rule java:S4551
In the first module (compiler with JDK 8), issue is not raised because the enum AWTUtilities.Translucency was removed in JDK 11, and because our Java analyzer is using the runtime JDK (11) it can't resolve the type.
In the second module (compiled with JDK 13), issue is not raised because the enum value Tree.Kind.SWITCH_EXPRESSION was introduced in JDK 12, and because our analyzer is using the runtime JDK (11) it can't resolve the type.