Skip to content

Commit 73b059f

Browse files
committed
Merge
2 parents 310a042 + 97a3d23 commit 73b059f

File tree

38 files changed

+1118
-304
lines changed

38 files changed

+1118
-304
lines changed

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2026, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it

src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535

3636
package java.util.concurrent;
3737

38+
import jdk.internal.misc.Unsafe;
39+
40+
import java.io.IOException;
41+
import java.io.ObjectInputStream;
42+
import java.io.ObjectStreamException;
43+
import java.io.Serial;
44+
import java.io.StreamCorruptedException;
3845
import java.util.AbstractSet;
3946
import java.util.Collection;
4047
import java.util.Iterator;
@@ -444,4 +451,38 @@ public Spliterator<E> spliterator() {
444451
return Spliterators.spliterator
445452
(al.getArray(), Spliterator.IMMUTABLE | Spliterator.DISTINCT);
446453
}
454+
455+
/**
456+
* De-serialization without data not supported for this class.
457+
*/
458+
@Serial
459+
private void readObjectNoData() throws ObjectStreamException {
460+
throw new StreamCorruptedException("Deserialized CopyOnWriteArraySet requires data");
461+
}
462+
463+
/**
464+
* Reconstitutes the {@code CopyOnWriteArraySet} instance from a stream
465+
* (that is, deserializes it).
466+
* @throws StreamCorruptedException if the object read from the stream is invalid.
467+
*/
468+
@Serial
469+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
470+
CopyOnWriteArrayList<E> newAl; // Set during the duplicate check
471+
472+
@SuppressWarnings("unchecked")
473+
CopyOnWriteArrayList<E> inAl = (CopyOnWriteArrayList<E>) in.readFields().get("al", null);
474+
475+
if (inAl == null
476+
|| inAl.getClass() != CopyOnWriteArrayList.class
477+
|| (newAl = new CopyOnWriteArrayList<>()).addAllAbsent(inAl) != inAl.size()) {
478+
throw new StreamCorruptedException("Content is invalid");
479+
}
480+
481+
final Unsafe U = Unsafe.getUnsafe();
482+
U.putReference(
483+
this,
484+
U.objectFieldOffset(CopyOnWriteArraySet.class, "al"),
485+
newAl
486+
);
487+
}
447488
}

0 commit comments

Comments
 (0)