[Java] Missing synchronized modifier on inherited method

java

(Werner Thumann) #1

Description
Any method which overrides a synchronized method should itself be synchronized. Else, relying on thread-safety through the base class most likely leads to concurrency problems.

Type
Bug

Snippet

public class MissingSynchronizedModifierOnInheritedMethod {

	public static class Base {
		public synchronized void method() {
			// impl
		}
	}
	
	public static class DerivedNoncompliant extends Base {
		@Override
		public void method() { // Noncompliant
			// impl
		}
	}
	
	public static class DerivedCompliant extends Base {
		@Override
		public synchronized void method() { // Compliant
			// impl
		}
	}
	
}

Note
Also covered by Eclipse JDT.


(Alexandre Gigleux) #5

Hello,

The specification was already there silently waiting to be implemented https://jira.sonarsource.com/browse/RSPEC-3551 (thanks @saberduck for the pointer).
I created https://jira.sonarsource.com/browse/SONARJAVA-2960 to add it to SonarJava’s backlog.

Regards