Skip to content

Commit e55224c

Browse files
Switch the pre22 warning to use CopyOnWriteArraySet. (#23969)
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 a7f14ce commit e55224c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
3232
import java.util.Collections;
33-
import java.util.HashSet;
3433
import java.util.Iterator;
3534
import java.util.List;
3635
import java.util.Map;
3736
import java.util.Set;
3837
import java.util.SortedMap;
3938
import java.util.TreeMap;
39+
import java.util.concurrent.CopyOnWriteArraySet;
4040
import java.util.logging.Logger;
4141

4242
/**
@@ -416,8 +416,7 @@ protected static IntList emptyIntList() {
416416
+ " security vulnerability:"
417417
+ " https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-h4h5-3hr4-j3g2";
418418

419-
protected static final Set<String> loggedPre22TypeNames =
420-
Collections.synchronizedSet(new HashSet<String>());
419+
protected static final Set<String> loggedPre22TypeNames = new CopyOnWriteArraySet<String>();
421420

422421
static void warnPre22Gencode(Class<?> messageClass) {
423422
if (System.getProperty(PRE22_GENCODE_SILENCE_PROPERTY) != null) {

0 commit comments

Comments
 (0)