S1604: Flagging implementations requring annotations as candidates for lambdas

I have a use case where I need to return an implementation of Runnable with the run method annotated, like so:

public org.springframework.core.task.TaskDecorator myTaskDecorator () {
	return runnable -> {
		return new Runnable() { // S1604 flagged here
			public void run() {
				// Some logic

Best I know, the new Runnable() above cannot be turned into a lambda as S1604 wants, while still being able to annotate the run method with @CustomAnnotation. So, IMO, S1604 should ignore cases where the single method has annotations, other than @Override.

Versions Used:
SonarQube Community Edition: v7.3.0
SonarJava: v5.6.1


For the record, I stumble into this old issue, and realized that it is still present in the current version of the analyzer!

I created a ticket (SONARJAVA-3358) to track this issue, and hopefully resolve this false positive.


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