FP on S2384 : Collections.singleton* calls should be considered as immutable

Hi
my version of SonarQube is Version 6.7.3 (build 38370) - LGPL v3 - Community


	private static final Set<String> set = Collections.singleton("Test");
	
	/**
	 * return the set.
	 * @return set.
	 */
	public Set<String> getSet() {
		return set;
	}
}

the attribute set in the method getSet() is flagged S2384
or the javadoc of Collections.singleton(T o) is : Returns an immutable set containing only the specified object. The returned set is serializable. javadoc

the rule must evolve to take into account this case.

Thanks

Regards

1 Like

we can see the same result on SonarCloud

Thank you, @sylvain_ridoux, for the detailed reproducers. I have opened SONARJAVA-2973 to track this false positive.

thank-you for your prompt response

1 Like