On Mon, 18 May 2026 12:24:27 GMT, Per Minborg <[email protected]> wrote:
>> This PR proposes to replace older `Collection.unmodifiable` wrappers with >> `Set.of()` instead. This can improve performance, reduce footprint, and >> reduce maintenance. There is also occasional use of `Map.of()` in nearby >> places where `Set.of()` was introduced. >> >> --------- >> - [X] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Per Minborg has updated the pull request incrementally with one additional > commit since the last revision: > > Revert change Looks OK - on the management side, there are a couple of others we could consider: diff --git a/src/java.management/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java b/src/java.management/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java index 4f26719d4f3..8210b293316 100644 --- a/src/java.management/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java +++ b/src/java.management/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java @@ -577,10 +577,7 @@ static <T> Descriptor makeDescriptor(OpenType<T> openType, if (defaultValue != null) map.put("defaultValue", defaultValue); if (legalValues != null) { - Set<T> set = new HashSet<>(); - for (T v : legalValues) - set.add(v); - set = Collections.unmodifiableSet(set); + Set<T> set = Set.of(legalValues); map.put("legalValues", set); } if (minValue != null) diff --git a/src/java.management/share/classes/javax/management/openmbean/CompositeType.java b/src/java.management/share/classes/javax/management/openmbean/CompositeType.java index 4db570be77c..f07d62b49d5 100644 --- a/src/java.management/share/classes/javax/management/openmbean/CompositeType.java +++ b/src/java.management/share/classes/javax/management/openmbean/CompositeType.java @@ -233,7 +233,7 @@ public Set<String> keySet() { // Initializes myNamesSet on first call if (myNamesSet == null) { - myNamesSet = Collections.unmodifiableSet(nameToDescription.keySet()); + myNamesSet = nameToDescription.keySet(); } return myNamesSet; // always return the same value ...in this second one maybe this keySet() method should just return nameToDescription.keySet(); not sure I see a great need for myNamesSet. Feel free to not do this if it's a more intrusive refactor than intended in this PR. 8-) ------------- PR Comment: https://git.openjdk.org/jdk/pull/31135#issuecomment-4613206600
