squid:UnusedPrivateMethod False Positive

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))
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
	}

}

Hi,

You are hitting this limitation of our semantic engine : 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.

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