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

java

(Sylvain Ridoux) #1

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


(Sylvain Ridoux) #2

we can see the same result on SonarCloud


(Andrei Epure) #3

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


(Sylvain Ridoux) #4

thank-you for your prompt response