A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5162 below:

False-positive when preceded by synchronized block · Issue #5162 · pmd/pmd · GitHub

Affects PMD Version:

7.4.0

Rule:

SingularField

Description:

SingularField incorrectly reports that a field could be a local variable if all methods where the variable is used contain a synchronized block before the use of the field.

The problem does not occur if the synchronized block comes after the use of the field, or if the synchronized block is removed. The problem also does not occur if there's another method in the class that uses the field and does not have a synchronized block before the use of the field.

Code Sample demonstrating the issue:

package test;

import java.util.List;

public class PmdBug {
	
	private List<String> sessions;

	public PmdBug(List<String> sessions) {
		this.sessions = sessions;
	}
	
	public void doStuff() {
		synchronized (this) {
			
		}
		
		sessions.stream().forEach(System.out::println);
	}
	
}

Expected outcome:

PMD should not report any violations. But it reports a violation at line 7.

Running PMD through:

Eclipse and Maven


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4