New Integer(String s) reported as Deprecated in Java 8 and IntelliJ 2019.1 beta


(Claudio Mezzasalma) #1

Hi all,

I think I just hit a false positive. I have this line in my project, using Java 8 as my SDK, IntelliJ 2019.1 beta:

Integer myInteger = new Integer(parameter.getUnescapedDefaultValue());

(where parameter.getUnescapedDefaultValue() returns a String).

SonarLint flags it as a Code Smell due to rule squid:CallToDeprecatedMethod; however, such constructor has been marked as @Deprecated in Java 9 and still not marked as that in Java 8.

My project is linked to SonarCloud, and via the SonarCloud web interface I see no issues on that line.

Hope this helps

(Michael Gumowski) #2

Hello @Lorthirk,

Thanks for the feedback. The fact that the issue is visible only on SonarLint and not on SonarCloud analysis makes me think that it’s related to the following issue: SONARJAVA-3056

To my point of view, it’s a problem of classloading. When in the context of SonarLint, I feel that the SonarJava analyzer is not relying on the classes from the correct JDK (somehow picking a SDK 9+ instead of 8, probably the one from your project). We experienced it a few times already, and tried to fix it in version 5.11 of SonarJava. Obviously that was not fully fixing it.