FP on squid:S2589 when values of variables changed only in listeners

SonarQube Version:
SonarJava Version: 5.14
Java Version: 1.8


Variable is set at beginning of a method. The value of the variable will be changed only in listeners.
SonarQube issues will be shown on conditions. The conditions should be changed so that they does not always evaluate to false/true.

Minimum code example:

public class BooleanExpression {
	private static boolean checkExpression = true;
	public static void main(String[] args) {
		// variable must be set else no sonar issue will be show in line 35
		checkExpression = false;
		JFrame frame = new JFrame("Test");
		JDialog dialog = new JDialog(frame, "Test Dialog");
		dialog.setSize(100, 100);
		// dialog must be modal. Condition should wait until Dialog is closed
		JButton button = new JButton("set True");
		// change value in listener
		button.addActionListener(e -> checkExpression = true);
		// Issue: Change this condition so that it does not always evaluate to "false"
		if (checkExpression) {
			System.out.println("checkExpression is true");

Hey Nicolas,

I can’t trigger S2589 on this code using SonarJava v6.0.1 – mind upgrading and trying again?

S2583 is triggered – is it possible you made a typo in your post?


1 Like

Hey Colin,

I missed negation in the condition. With negation it’s S2589 without S2583 but I would say both cases are fp.


Hello @Nicolas,

I just checked, and it seems that this FP is still present on the current version, I therefore created a ticket (SONARJAVA-3319) to track it.

Thanks for taking time to report it, and providing a code example!


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