# False "Remove this unused import java:S1128" issues after update to version 8.7.1

**URL:** <https://community.sonarsource.com/t/false-remove-this-unused-import-java-s1128-issues-after-update-to-version-8-7-1/40305>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [March 18, 2021, 12:57pm UTC](https://community.sonarsource.com/t/false-remove-this-unused-import-java-s1128-issues-after-update-to-version-8-7-1/40305 "2021-03-18T12:57:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcelRueedi](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcelrueedi/32/20386_2.png) [@MarcelRueedi](https://community.sonarsource.com/u/MarcelRueedi)\
**Post date:** [March 18, 2021, 12:57pm UTC](https://community.sonarsource.com/t/false-remove-this-unused-import-java-s1128-issues-after-update-to-version-8-7-1/40305/1 "2021-03-18T12:57:08Z")

</div>

We updated our SonarQube Server to 8.7.1 on 15.3.2021

- SonarQube ID information  
Server ID: A7EE8CF2-AWNfJ7jrUMoe9cI1imbB  
Version: 8.7.1.42226

Now there are 14 new issues “Remove this unused import” but all of them are false, because the removal would result in a compilation error.

This java class produces : Remove this unused import ‘com.example.client.common.editor.view.BaseEditorPart.TRANSIENT\_PARAMETER\_READONLY’.

```auto
package com.example.client.selection.handler;

import static com.example.client.common.editor.view.BaseEditorPart.TRANSIENT_PARAMETER_READONLY;
import static java.util.Objects.nonNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.example.client.common.part.PartManager;
import com.example.shared.dto.DataSetVersionIdDTO;

public abstract class BasePartHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(BasePartHandler.class);

    protected final PartManager partManager;

    protected BasePartHandler(PartManager partManager) {
        this.partManager = partManager;
    }

    protected void displayPart(String partId) {
        displayPartInternal(partId, null, null, null);
    }

    protected void displayPart(String partId, String parameterName, DataSetVersionIdDTO id) {
        displayPartInternal(partId, parameterName, id, null);
    }

    protected void displayPartEditable(String partId) {
        displayPartInternal(partId, null, null, false);
    }

    protected void displayPartEditable(String partId, String parameterName, DataSetVersionIdDTO id) {
        displayPartInternal(partId, parameterName, id, false);
    }

    protected void displayPartReadOnly(String partId) {
        displayPartInternal(partId, null, null, true);
    }

    protected void displayPartReadOnly(String partId, String parameterName, DataSetVersionIdDTO id) {
        displayPartInternal(partId, parameterName, id, true);
    }

    private void displayPartInternal(String partId, String parameterName, DataSetVersionIdDTO id, Boolean readOnly) {
        try {
            partManager.displayPart(partId, partManager.createElementId(partId, id, readOnly),
                    part -> {
                        if (nonNull(parameterName) && nonNull(id)) {
                            part.getTransientData().put(parameterName, id);
                        }
                        if (nonNull(readOnly)) {
                            part.getTransientData().put(TRANSIENT_PARAMETER_READONLY, readOnly);
                        }
                    });
        } catch (Exception ex) {
            LOGGER.error(getErrorMessage(), ex);
        }
    }

    protected void hidePart(String elementId) {
        partManager.hidePart(elementId);
    }

    protected abstract String getErrorMessage();
}

```

---

<div class="post-metadata">

**Author:** ![Quentin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/quentin/32/74716_2.png) [@Quentin](https://community.sonarsource.com/u/Quentin)\
**Post date:** [April 21, 2021, 12:28pm UTC](https://community.sonarsource.com/t/false-remove-this-unused-import-java-s1128-issues-after-update-to-version-8-7-1/40305/2 "2021-04-21T12:28:20Z")

</div>

Hello @MarcelRueedi

Indeed, this rule is subject to few false positives and the situation you are reporting is one of them. The good news is that we identify a way to greatly improve the precision of this rule, see [SONARJAVA-3777](https://jira.sonarsource.com/browse/SONARJAVA-3777). Once implemented, it should most probably solve your problem.

Best,  
Quentin

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [April 28, 2021, 12:28pm UTC](https://community.sonarsource.com/t/false-remove-this-unused-import-java-s1128-issues-after-update-to-version-8-7-1/40305/3 "2021-04-28T12:28:52Z")

</div>

Closed on April 28, 2021, 12:28pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
