# Remove useless assignment

**URL:** <https://community.sonarsource.com/t/remove-useless-assignment/149834>\
**Category:** Report False-positive / False-negative...\
**Created:** [October 5, 2025, 8:18pm UTC](https://community.sonarsource.com/t/remove-useless-assignment/149834 "2025-10-05T20:18:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damon\_Sutherland](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/damon_sutherland/32/54735_2.png) [@Damon\_Sutherland](https://community.sonarsource.com/u/Damon_Sutherland)\
**Post date:** [October 5, 2025, 8:18pm UTC](https://community.sonarsource.com/t/remove-useless-assignment/149834/1 "2025-10-05T20:18:53Z")

</div>

Please provide

- Operating system: MacOS (Sequoia 15.7.1)
- SonarQube for IntelliJ plugin version:
- IntelliJ version: 11.2.0.82481
- Programming language you’re coding in: Java
- Is connected mode used: No
  - SonarQube Cloud, SonarQube Server, or SonarQube Community Build? (if one of the latter two, which version?):

And a thorough description of the problem / question:

I frequently get warnings to “Remove useless assignments”. These are frequently false positives:

For example:

```java
class Partial {

    private final Map<Class<?>, Supplier<?>> registry = new HashMap<>();

    ...

    private <T> T build(Class<?> clazz, Supplier<T> supplier) {
        return (T) registry.computeIfAbsent(clazz, k -> supplier).get();
    }

    public void activateSubdomain(Subdomain.ActivateSubdomainRequest ... requests) {
        // WARNING: Remove this useless assignment to local variable "subdomains".
        var subdomains = build(SubdomainsDAO.class, () -> new PostgresSubdomainsDAO(jdbi, ids));
        for (var request : requests) {
            subdomains.activateSubdomain(request.subdomainId(), request.labelId(), null);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 7, 2025, 3:08pm UTC](https://community.sonarsource.com/t/remove-useless-assignment/149834/2 "2025-10-07T15:08:21Z")

</div>

Hey there.

We often see FPs on this rule when the semantic is not complete ([Jira](https://sonarsource.atlassian.net/browse/SONARJAVA-4960)).

In your IDE, has your project been rebuilt? Does doing so make the issue go away?

> [@Unresolved variable in anonymous class (S1854: Remove this useless assignment to local variable "!unknown!")](https://community.sonarsource.com/t/unresolved-variable-in-anonymous-class-s1854-remove-this-useless-assignment-to-local-variable-unknown/46076/7):
>
> Finally coming back at this, we are currently putting a lot of effort to avoid reporting issues when things are unresolved. The first observation is that I was still unable to reproduce the issue… Still, during the investigation, I manage to identify problems in the logic to determine what is unresolved or not (see [SONARJAVA-4126](https://jira.sonarsource.com/browse/SONARJAVA-4126)). It should improve things, but I’m unsure this will solve your specific problem. This report is now quite old, a lot of changes happened since. I encourage anyone f…
