# Sonarlint rule java:S2386 not working properly

**URL:** <https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490>\
**Category:** Report False-positive / False-negative...\
**Tags:** sonarqube-ide, java\
**Created:** [April 22, 2020, 3:50pm UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490 "2020-04-22T15:50:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LoadingBG](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/loadingbg/32/10857_2.png) [@LoadingBG](https://community.sonarsource.com/u/LoadingBG)\
**Post date:** [April 22, 2020, 3:50pm UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/1 "2020-04-22T15:50:58Z")

</div>

```auto
public static final Map<String, ArrayList<Command>> customCommands = new HashMap<>();
public static final Map<String, ArrayList<Command>> coreCommands = new HashMap<>();

```

I have these two lines in my code. These are fields of a class. Even though they are declared as `final`, Sonarlint gives a positive for rule java:S2386 `"Mutable fields should not be "public static""`.

* * *
I'm working in Eclipse IDE using JDK 13. Sonarlint's version is 5.0.

---

<div class="post-metadata">

**Author:** ![CrushaKRool](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/crushakrool/32/6541_2.png) [@CrushaKRool](https://community.sonarsource.com/u/CrushaKRool)\
**Post date:** [April 22, 2020, 7:17pm UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/2 "2020-04-22T19:17:32Z")

</div>

Even if they were final, the collection itself is still mutable. I believe Sonar would not report an issue if they were wrapped via **Collections.unmodifiableMap()**, but you would need to adapt your code so that all values are assigned at initialization of the variables.

---

<div class="post-metadata">

**Author:** ![saisuryakat](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/saisuryakat/32/11819_2.png) [@saisuryakat](https://community.sonarsource.com/u/saisuryakat)\
**Post date:** [May 19, 2020, 7:47am UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/3 "2020-05-19T07:47:29Z")

</div>

I’m using java 11’s Map.ofEntries(entry(), entry()…);  
This utility returns an unmodifiable map, but SonarLint still complains to make it protected

---

<div class="post-metadata">

**Author:** ![saisuryakat](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/saisuryakat/32/11819_2.png) [@saisuryakat](https://community.sonarsource.com/u/saisuryakat)\
**Post date:** [May 25, 2020, 11:01am UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/4 "2020-05-25T11:01:13Z")

</div>

@CrushaKRool should I raise new bug ?

---

<div class="post-metadata">

**Author:** ![Quentin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/quentin/32/74716_2.png) [@Quentin](https://community.sonarsource.com/u/Quentin)\
**Post date:** [May 25, 2020, 12:03pm UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/6 "2020-05-25T12:03:45Z")

</div>

Hello @saisuryakat,

> should I raise new bug ?

Since your problem is targetting another case and the initial question is marked with a solution, the good way to go would indeed be to create a new post. It will help to not go unnoticed for too long.

In this case, no need to create another one, I agree with you and created a ticket thanks to your feedback ([SONARJAVA-3429](https://jira.sonarsource.com/browse/SONARJAVA-3429)).

Best,  
Quentin

---

<div class="post-metadata">

**Author:** ![saisuryakat](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/saisuryakat/32/11819_2.png) [@saisuryakat](https://community.sonarsource.com/u/saisuryakat)\
**Post date:** [May 25, 2020, 2:30pm UTC](https://community.sonarsource.com/t/sonarlint-rule-java-s2386-not-working-properly/23490/8 "2020-05-25T14:30:08Z")

</div>

Thank you @Quentin
