Skip to content

Commit

Permalink
Add violations for Maps and Sets with expeted size
Browse files Browse the repository at this point in the history
Fixes #258.
  • Loading branch information
gaul committed Dec 3, 2024
1 parent 7d81cb9 commit a553adf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modernizer-maven-plugin/src/main/resources/modernizer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ violation names use the same format that javap emits.
<comment>Prefer java.util.HashMap&lt;&gt;(java.util.Map)</comment>
</violation>

<violation>
<name>com/google/common/collect/Maps.newHashMapWithExpectedSize:(I)Ljava/util/HashMap;</name>
<version>19</version>
<comment>Prefer java.util.HashMap&lt;&gt;(int)</comment>
</violation>

<violation>
<name>com/google/common/collect/Maps.newIdentityHashMap:()Ljava/util/IdentityHashMap;</name>
<version>7</version>
Expand All @@ -155,6 +161,12 @@ violation names use the same format that javap emits.
<comment>Prefer java.util.LinkedHashMap&lt;&gt;()</comment>
</violation>

<violation>
<name>com/google/common/collect/Maps.newLinkedHashMapWithExpectedSize:(I)Ljava/util/LinkedHashMap;</name>
<version>19</version>
<comment>Prefer java.util.LinkedHashMap.newLinkedHashMap&lt;&gt;(int)</comment>
</violation>

<violation>
<name>com/google/common/collect/Maps.newLinkedHashMap:(Ljava/util/Map;)Ljava/util/LinkedHashMap;</name>
<version>7</version>
Expand Down Expand Up @@ -203,12 +215,24 @@ violation names use the same format that javap emits.
<comment>Prefer java.util.HashSet&lt;&gt;()</comment>
</violation>

<violation>
<name>com/google/common/collect/Sets.newHashSetWithExpectedSize:(I)Ljava/util/HashSet;</name>
<version>19</version>
<comment>Prefer java.util.HashSet&lt;&gt;(int)</comment>
</violation>

<violation>
<name>com/google/common/collect/Sets.newLinkedHashSet:()Ljava/util/LinkedHashSet;</name>
<version>7</version>
<comment>Prefer java.util.LinkedHashSet&lt;&gt;()</comment>
</violation>

<violation>
<name>com/google/common/collect/Sets.newLinkedHashSetWithExpectedSize:(I)Ljava/util/LinkedHashSet;</name>
<version>19</version>
<comment>Prefer java.util.LinkedHashSet.newLinkedHashSet&lt;&gt;(int)</comment>
</violation>

<violation>
<name>com/google/common/collect/Sets.newSetFromMap:(Ljava/util/Map;)Ljava/util/Set;</name>
<version>7</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,10 @@ private static void method() throws Exception {
new Locale("", "");
new Locale("", "", "");
new Thread().getId();
Maps.newHashMapWithExpectedSize(0);
Maps.newLinkedHashMapWithExpectedSize(0);
Sets.newHashSetWithExpectedSize(0);
Sets.newLinkedHashSetWithExpectedSize(0);
}
}

Expand Down

0 comments on commit a553adf

Please sign in to comment.