False-positive java:S1128 unnecessary import

Template for a good bug report, formatted with Markdown:

  • versions used: SonarLint plugin ( with Intellij

(IntelliJ IDEA 2020.2.2 (Ultimate Edition)
Build #IU-202.7319.50, built on September 15, 2020
Runtime version: 11.0.8+10-b944.31 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7)

  • error observed (wrap logs/code around triple quote ``` for proper formatting)
Remove this unused import 'com.cartrust.comregistraiton.organiozation.model.DocumentState.UPLOADED'
  • steps to reproduce

It seem related to the enum value “UPLOADED” if I refactor the value to “UPLOADED_YEAH” the error disappears. Of course it was used after the refactoring too.

Other enum values from the same enum are not shown as errors:

import static com.cartrust.registration.organization.model.DocumentState.MISSING;
import static com.cartrust.registration.organization.model.DocumentState.UPLOADED;
import static com.cartrust.registration.organization.model.DocumentState.WAITING_FOR_NOTIFICATION;
import static com.cartrust.registration.organization.model.DocumentState.WAITING_FOR_UPLOAD;

Here’s the usage in the same file:

  public void on(DocumentAddedEvent event) {
    val aggregateId = event.getOwnerOrganizationId();

        organizationView -> {
  • potential workaround

Rename enum values “UPLOADED” to something else.

P.S.: use the #bug:fault sub-category if you’re hitting a specific crash/error , or the #bug:fp sub-category for rules-related behaviour

Hello @tim-comline,

Sorry for coming back to you so late after you posted this. Unfortunately, without a self-contained reproducer code, it will be hard for me to reproduce the issue on my side, as I can only assumes on what are the methods used in the code snippet. Can you simplify your code snippet and provide a code which which explicitly reproduce the issue without having to figure some methods?

Also, I guess that you are using lombok (val?), and we have always been facing issue handling it correctly in our analysis. It might be a track to explore.