False Positive: S1450 - Private fields only used as local variables in methods should become local variables

This code produces a false postive with the message Remove the a field and declare it as a local variable in the relevant methods in line 5.

import B;

public class A {

	private Object a;

	public void f(Object a) {
		this.a = a;
		B.f(a);
	}

	public void g() {
		B.h(() -> {
			B.k(a);
		});
	}
}

Seems like it has something to do with the lambda in method g.

Hello @ann-sophie and welcome to the SonarSource community!

Thanks for taking the time to report this issue, I managed to reproduce it.

Note that it seems to me that this is only a temporary FP: I managed to reproduce it when I just pasted the code, if I build the project, the issue disappears.

In any way, I think we should do something to improve the situation, as it may happen in other situations. Ticket created: SONARJAVA-4109.

Best,
Quentin

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