Skip to content

Commit 9822fb5

Browse files
Switch the pre22 warning to use CopyOnWriteArraySet. (#23976)
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 #23963 PiperOrigin-RevId: 819238880 Co-authored-by: Protobuf Team Bot <[email protected]>
1 parent 6fbcb87 commit 9822fb5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

java/core/src/main/java/com/google/protobuf/GeneratedMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import java.lang.reflect.Method;
2222
import java.util.ArrayList;
2323
import java.util.Collections;
24-
import java.util.HashSet;
2524
import java.util.Iterator;
2625
import java.util.List;
2726
import java.util.Map;
2827
import java.util.Set;
2928
import java.util.TreeMap;
29+
import java.util.concurrent.CopyOnWriteArraySet;
3030
import java.util.logging.Logger;
3131

3232
/**
@@ -331,8 +331,9 @@ public int getSerializedSize() {
331331
+ " security vulnerability:"
332332
+ " https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-h4h5-3hr4-j3g2";
333333

334-
private static final Set<String> loggedPre22TypeNames
335-
= Collections.synchronizedSet(new HashSet<String>());
334+
protected static final Set<String> loggedPre22TypeNames =
335+
new CopyOnWriteArraySet<String>();
336+
336337
static void warnPre22Gencode(Class<?> messageClass) {
337338
if (System.getProperty(PRE22_GENCODE_SILENCE_PROPERTY) != null) {
338339
return;

0 commit comments

Comments
 (0)