# squid:UnusedPrivateMethod False Positive

**URL:** <https://community.sonarsource.com/t/squid-unusedprivatemethod-false-positive/7551>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [March 7, 2019, 10:47am UTC](https://community.sonarsource.com/t/squid-unusedprivatemethod-false-positive/7551 "2019-03-07T10:47:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jburgel](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jburgel](https://community.sonarsource.com/u/jburgel)\
**Post date:** [March 7, 2019, 10:47am UTC](https://community.sonarsource.com/t/squid-unusedprivatemethod-false-positive/7551/1 "2019-03-07T10:47:42Z")

</div>

The rule  
squid:UnusedPrivateMethod is incorrectly flagged on actually used private method, which has the same name as another method in the same class .

- versions used (6.7.6 version of sonarqube, Sonar java version 5.11 (build 17289))

```auto
import java.util.ArrayList;
import java.util.List;

public class A {

	private List<B> values = new ArrayList<>();

	public List<B> getValues() {
		return values;
	}

	public void setValues(List<B> values) {
		this.values = values;
	}
}

import java.util.ArrayList;
import java.util.List;

public class B {

	private List<C> values = new ArrayList<>();

	public List<C> getValues() {
		return values;
	}

	public void setValues(List<C> values) {
		this.values = values;
	}
}

public class C {

}

import java.util.List;

public class WrongClass {

	void testMethod(A object) {
		object.getValues().stream().forEach(value -> testMethod(value.getValues()));
	}

	private void testMethod(List<C> list) { // would be reported as unused private method, even though it is used
		//implementation
	}

}
```

---

<div class="post-metadata">

**Author:** ![Nicolas\_Peru](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicolas_peru/32/22_2.png) [@Nicolas\_Peru](https://community.sonarsource.com/u/Nicolas_Peru)\
**Post date:** [July 10, 2019, 12:52pm UTC](https://community.sonarsource.com/t/squid-unusedprivatemethod-false-positive/7551/2 "2019-07-10T12:52:12Z")

</div>

Hi,

You are hitting this limitation of our semantic engine : [https://jira.sonarsource.com/browse/SONARJAVA-2084](https://jira.sonarsource.com/browse/SONARJAVA-2084)  
This is something really not straightforward to solve.  
We have in the pipe to workaround this by using another frontend for SonarJava and thus benefiting from its semantic. This is still early to commit to anything but it is ongoing.

In the meantime the workaround is, unfortunately, to mark the issue as false positive.

---

<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 8, 2021, 9:26am UTC](https://community.sonarsource.com/t/squid-unusedprivatemethod-false-positive/7551/3 "2021-04-08T09:26:58Z")

</div>

Closed on April 8, 2021, 9:26am UTC

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