--- old/src/java.base/share/classes/java/nio/channels/UnixDomainSocketAddress.java 2020-07-02 17:52:57.000000000 +0100
+++ new/src/java.base/share/classes/java/nio/channels/UnixDomainSocketAddress.java 2020-07-02 17:52:56.000000000 +0100
@@ -48,26 +48,77 @@
* @since 16
*/
public final class UnixDomainSocketAddress extends SocketAddress {
+ @java.io.Serial
static final long serialVersionUID = 92902496589351288L;
- private final Path path;
+ private final transient Path path;
- static class SerializationProxy implements Serializable {
- static final long serialVersionUID = 9829020419651288L;
+ /**
+ * A serial proxy for all {@link UnixDomainSocketAddress} instances.
+ * It captures the file path name and reconstructs using the public static
+ * {@link #of(String) factory}.
+ *
+ * @serial include
+ */
+ private static final class SerialProxy implements Serializable {
+ @java.io.Serial
+ static final long serialVersionUID = -7955684448513979814L;
- private String pathname;
+ /**
+ * The path name.
+ * @serial
+ */
+ private final String pathname;
- SerializationProxy(UnixDomainSocketAddress addr) {
- this.pathname = addr.path.toString();
+ SerialProxy(String pathname) {
+ this.pathname = pathname;
}
+ /**
+ * Creates a {@link UnixDomainSocketAddress} instance, by an invocation
+ * of the {@link #of(String) factory} method passing the path name.
+ * @return a UnixDomainSocketAddress
+ */
+ @java.io.Serial
private Object readResolve() {
return UnixDomainSocketAddress.of(pathname);
}
}
+ /**
+ * Returns a
+ *
+ * SerialProxy containing the path name of this instance.
+ *
+ * @return a {@link SerialProxy}
+ * representing the path name of this instance
+ */
+ @java.io.Serial
private Object writeReplace() throws ObjectStreamException {
- return new SerializationProxy(this);
+ return new SerialProxy(path.toString());
+ }
+
+ /**
+ * Throws InvalidObjectException, always.
+ * @param s the stream
+ * @throws java.io.InvalidObjectException always
+ */
+ @java.io.Serial
+ private void readObject(java.io.ObjectInputStream s)
+ throws java.io.InvalidObjectException
+ {
+ throw new java.io.InvalidObjectException("Proxy required");
+ }
+
+ /**
+ * Throws InvalidObjectException, always.
+ * @throws java.io.InvalidObjectException always
+ */
+ @java.io.Serial
+ private void readObjectNoData()
+ throws java.io.InvalidObjectException
+ {
+ throw new java.io.InvalidObjectException("Proxy required");
}
private UnixDomainSocketAddress(Path path) {
--- old/test/jdk/java/nio/channels/unixdomain/UnixDomainSocketAddressSerializationTest.java 2020-07-02 17:52:59.000000000 +0100
+++ new/test/jdk/java/nio/channels/unixdomain/UnixDomainSocketAddressSerializationTest.java 2020-07-02 17:52:59.000000000 +0100
@@ -25,15 +25,19 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
import java.io.IOException;
+import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.nio.channels.UnixDomainSocketAddress;
import java.nio.file.Path;
-
+import static java.io.ObjectStreamConstants.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
/*
* @test
@@ -60,6 +64,13 @@
assertEquals(deserialized, addr);
}
+ static final Class IOE = InvalidObjectException.class;
+
+ /** Tests that UnixDomainSocketAddress in the byte-stream is disallowed. */
+ public static void testUnixDomainSocketAddressInStream() {
+ expectThrows(IOE, () -> deserialize(byteStream(), UnixDomainSocketAddress.class));
+ }
+
private static byte[] serialize(T t)
throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -78,4 +89,28 @@
return cl.cast(o);
}
}
+
+ static final String CLASSNAME = UnixDomainSocketAddress.class.getName();
+ static final long SUID = ObjectStreamClass.lookup(UnixDomainSocketAddress.class).getSerialVersionUID();
+ /**
+ * Returns a stream with UnixDomainSocketAddress in the stream. The
+ * stream will have no stream field values.
+ */
+ static byte[] byteStream() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+ dos.writeShort(STREAM_MAGIC);
+ dos.writeShort(STREAM_VERSION);
+ dos.writeByte(TC_OBJECT);
+ dos.writeByte(TC_CLASSDESC);
+ dos.writeUTF(CLASSNAME);
+ dos.writeLong(SUID);
+ dos.writeByte(SC_SERIALIZABLE);
+ dos.writeShort(0); // number of stream fields
+ dos.writeByte(TC_ENDBLOCKDATA); // no annotations
+ dos.writeByte(TC_NULL); // no superclasses
+ dos.write(TC_ENDBLOCKDATA); // end block - for SC_WRITE_METHOD
+ dos.close();
+ return baos.toByteArray();
+ }
}