From cd94c7aa0dccf5fc7d8f6ee80dc7c916213b4cdb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 14 Oct 2025 08:38:31 -0700 Subject: [PATCH] Switch the pre22 warning to use CopyOnWriteArraySet. This data structure is better for cases where writes are rare and reads common. When this warning path is it, the writes only occur exactly once per CVE-affected type, and reads occur once per every parse of those types. Broadly people sensitive by this performance concern should really regen their gencode, but this should help take the edge off of people who first upgrade to 4.x and then look to incrementally regen any ancient gencode. Fixes https://github.com/protocolbuffers/protobuf/issues/23963 PiperOrigin-RevId: 819238880 --- .../src/main/java/com/google/protobuf/GeneratedMessage.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index 5346a6bda6339..707a8ff10f3d2 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -30,13 +30,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Logger; /** @@ -416,8 +416,7 @@ protected static IntList emptyIntList() { + " security vulnerability:" + " https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-h4h5-3hr4-j3g2"; - protected static final Set loggedPre22TypeNames = - Collections.synchronizedSet(new HashSet()); + protected static final Set loggedPre22TypeNames = new CopyOnWriteArraySet(); static void warnPre22Gencode(Class messageClass) { if (System.getProperty(PRE22_GENCODE_SILENCE_PROPERTY) != null) {