# S1854 FP - Remove this useless assignment to local variable

**URL:** <https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750>\
**Category:** Report False-positive / False-negative...\
**Tags:** sonarqube\
**Created:** [June 24, 2024, 10:47am UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750 "2024-06-24T10:47:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 10:47am UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/1 "2024-06-24T10:47:28Z")

</div>

Make sure to read this post before raising a thread here:

> [@How to Report a False-positive / False-negative](https://community.sonarsource.com/t/how-to-report-a-false-positive-false-negative/37022):
>
> Hey SonarSource Community! [False-positives happen](https://blog.sonarsource.com/false-positives-our-enemies-but-maybe-your-friends), as do false-negatives, and we’re eager to fix them. We are thrilled when our users report problems, so we can make our products better. What is a false-positive (FP)? A false-positive is when an issue is raised unexpectedly on code that should not trigger an issue, or where the suggested action doesn’t make any sense for the code. What is a false-negative (FN)? A false-negative is when an issue should be raised on a piece of code, but isn’t. …

Then tell us:

Java  
SonarQube v10.5.1

Indicates useless assignment to ‘METHOD’

```
private static void rollbackOrCommit(DBConnection theDB)
{
    final String METHOD = CLASS + ".rollbackOrCommit";

    if (theDB != null)
    {
		if (theDB.doRollbackOnError)
		{
			theDB.rollback();
		}
		else
		{
			try
			{
				theDB.commit();
			}
			catch (SQLException ex)
			{
				Log.log(1, METHOD, "dberror", Log.ERROR, "", "", "");
				theDB.rollback();
			}
        }
    }
}

```

---

<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:** [June 24, 2024, 12:09pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/2 "2024-06-24T12:09:38Z")

</div>

Hey there.

We know that sometimes this rule raises false-positives when the “semantic” is incomplete: [SONARJAVA-4960](https://sonarsource.atlassian.net/browse/SONARJAVA-4960)

How do you execute your analysis (which scanner do you use? the SonarScanner CLI, the SonarScanner for Maven? Gradle?)

Do you receive any warnings during the analysis?

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 12:26pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/3 "2024-06-24T12:26:53Z")

</div>

I don’t know what ‘semantic’ is incomplete refers to. We are getting about 90 of these false positives.

The SonarQube is being executed from a Jenkins build

I took some screen capture below

 ![](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/7/6758cad404c18a9535678557bb3e052106b3b34a.png)

 ![image002.png](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/4/5/45473749a5aa52ec21fe1df07fe583f1fccf543a.png)

---

<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:** [June 24, 2024, 12:28pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/4 "2024-06-24T12:28:14Z")

</div>

> [@dandoy](#):
>
> The SonarQube is being executed from a Jenkins build

How about you share how your Jenkins build is configured?

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 12:29pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/5 "2024-06-24T12:29:03Z")

</div>

The code all compiles.

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 12:34pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/6 "2024-06-24T12:34:34Z")

</div>

They all seem to deal with catching SQLException and the variable is only being used in the catch block.

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 12:43pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/7 "2024-06-24T12:43:07Z")

</div>

I have a attached the groovy file. I don’t really know much about the Jenkins build.

(Attachment MCS\_CommitBuild.groovy is missing)

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 24, 2024, 12:47pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/8 "2024-06-24T12:47:58Z")

</div>

Zip file blocked on our side. Here is partial screen capture.

 ![](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/7/576579a39ff939d09be0f193a05a12e24688d67f.png)

---

<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:** [June 25, 2024, 9:35am UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/9 "2024-06-25T09:35:49Z")

</div>

Hey again.

Indeed, it looks like you’re running the [SonarScanner CLI](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/), which isn’t the recommended way (unless your normal build tool is an ant, in which case it’s the only way).

This is because the SonarScanner CLI requires a lot of manual configuration to perform an accurate analysis of Java, specifically the [bytecode](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/java/#analysis-and-bytecode) (the “semantic” I was referring to earlier)

I’m not sure what build tool is underneath your `make` commands are hiding. Can you tell me more about how your Java code is compiled?

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 26, 2024, 3:33pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/10 "2024-06-26T15:33:40Z")

</div>

Yes, we are using ant as the build tool, but don’t really understand how the build tool impacts the sonar analysis since the source and byte code generated are not really dependent on the build tool that is utilized. Java is still responsible for generating the byte code and not the build tool.

---

<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:** [June 27, 2024, 12:55pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/11 "2024-06-27T12:55:27Z")

</div>

Yes, but how that bytecode makes its way to the scanner to help analysis is build-tool dependent (and for Maven and Gradle, we can pick up those paths automatically).

We have documented a migration path from the [SonarScanner for Ant to the SonarScanner CLI](https://docs.sonarsource.com/sonarqube/10.5/analyzing-source-code/scanners/sonarscanner-for-ant/). You weren’t ever using the SonarScanner for Ant, but the general advice (add `sonar.java.*` to a _sonar-project.properties_ file) still applies.

Once the proper bytecode is being read into your analysis, these FPs on S1854 should go away.

---

<div class="post-metadata">

**Author:** ![dandoy](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dandoy](https://community.sonarsource.com/u/dandoy)\
**Post date:** [June 27, 2024, 2:10pm UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/12 "2024-06-27T14:10:04Z")

</div>

We already have the following in our properties file:

sonar.sources=src/classmcs,src/legacy

sonar.java.binaries=classes/legacy,classes/classmcs

sonar.java.libraries=serverLib,springbootLib,clientLib,smartFactoryLib,3rdParty

Is there something else we need to add.

---

<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:** [July 2, 2024, 8:18am UTC](https://community.sonarsource.com/t/s1854-fp-remove-this-useless-assignment-to-local-variable/117750/13 "2024-07-02T08:18:25Z")

</div>

Ideally, no, if all that information is complete and correct.

I have a feeling to learn more, we’d need to see the complete output of the `sonar-scanner` at DEBUG level (`sonar-scanner -X`)
