'Sonar Make this member "protected"/ Mutable fields should not be "public static" with Streams
I have added sonar to my project and I am getting Make this member "protected" issue.
I am getting this on a public static final set.
I already have gone through the documents and I know why this is an issue. We can resolve this by using unmodifiable set.
REF: Reference_1 Reference_2
My question is I am getting this issue if I am using streams( Collectors.collectingAndThen(...) or Collectors.toUnmodifiableSet()) to get an unmodifiable set.
Details:
Sonar issue is gone with the below code method of getting UnModifiableList;
Set<String> set = Collectors.toUnmodifiableSet(Stream.of("USA", "UK", "India")
.collect(Collectors.toSet()));
Issue still present if I am using Collectors.collectingAndThen() or
Collectors.toUnmodifiableSet()
Sample Code:
Set<String> set = Stream.of("USA", "UK", "India")
.collect(Collectors.collectingAndThen(Collectors.toSet(),
Collections::unmodifiableSet));
OR
Set<String> set = Stream.of("USA", "UK", "India")
.collect(Collectors.toUnmodifiableSet());
The codes above will give an UnmodifiableSet so why Sonar is marking this as an issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
