False positive issue <Unnecessary imports should be removed>

The sonar reports the “Remove this unused import ‘java.lang.System.lineSeparator’” error for the below mentioned line of code:

import static java.lang.System.lineSeparator;

While I know that the java.lang imports are not required to be manually declared into the source code, this is not true for the static imports. The developers can use the static imports just to make the code shorter and/or cleaner. Exactly this is the case in our code as well.

Version 6.7.1.35068
java.version 1.8.0_131
SonarJava version: 5.13.1 (build 18282)
IDE: Spring Tool Suite 4.4.1.RELEASE

Hi @ART515,

and the issue is telling you that lineSeparator static import is unused in its context, is it the case?

Hi @mpaladin,

We are getting this report:

image

Here is another image about the same error:

Hello @ART515,

I managed to reproduce the false positive on SonarJava version < 6.0, but not with a version > 6.0.

A lot happened in 6.0, I expect this resolution to be a nice side effect of this effort!

Best,
Quentin

1 Like