FP on S2384 and Collections.emptyList()

I believe the warning in the following code should not be raised, because Collections.emptyList() is immutable:

import java.util.Collections;
import java.util.List;

class S2384 {
	private final List<String> myList = Collections.emptyList();

	public List<String> getMyList() {
		return myList; // SonarLint: Return a copy of "myList". 

This warning is reported by SonarLint for IntelliJ

1 Like

Hello @bjansen

Thanks for the clear description of the issue and the clear reproducer. It makes sense to me, ticket created: SONARJAVA-4123.


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