8229997: Apply java.io.Serial annotations in java.base

Reviewed-by: alanb, rriggs
This commit is contained in:
Joe Darcy 2019-08-29 16:31:34 -07:00
parent 6d064a747e
commit 9d764ee48e
315 changed files with 880 additions and 254 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ package java.net;
*/
public class BindException extends SocketException {
@java.io.Serial
private static final long serialVersionUID = -5945005768251722951L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ package java.net;
* @since 1.1
*/
public class ConnectException extends SocketException {
@java.io.Serial
private static final long serialVersionUID = 3831404271622369215L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import java.io.IOException;
*/
public
class HttpRetryException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -9186022286469111381L;
private int responseCode;

View file

@ -89,6 +89,7 @@ class Inet4Address extends InetAddress {
/** use serialVersionUID from InetAddress, but Inet4Address instance
* is always replaced by an InetAddress instance before being
* serialized */
@java.io.Serial
private static final long serialVersionUID = 3286316764910316507L;
/*
@ -134,6 +135,7 @@ class Inet4Address extends InetAddress {
* @throws ObjectStreamException if a new object replacing this
* object could not be created
*/
@java.io.Serial
private Object writeReplace() throws ObjectStreamException {
// will replace the to be serialized 'this' object
InetAddress inet = new InetAddress();

View file

@ -363,6 +363,7 @@ class Inet6Address extends InetAddress {
private final transient Inet6AddressHolder holder6;
@java.io.Serial
private static final long serialVersionUID = 6880410070516793377L;
// Perform native initialization
@ -562,7 +563,7 @@ class Inet6Address extends InetAddress {
* @serialField scope_ifname_set boolean
* @serialField ifname String
*/
@java.io.Serial
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("ipaddress", byte[].class),
new ObjectStreamField("scope_id", int.class),
@ -581,6 +582,7 @@ class Inet6Address extends InetAddress {
* including the scope information, only if the
* scoped interface name is valid on this system
*/
@java.io.Serial
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
NetworkInterface scope_ifname = null;
@ -644,6 +646,7 @@ class Inet6Address extends InetAddress {
* scope_ifname field as a String, rather than a NetworkInterface
* which is not serializable
*/
@java.io.Serial
private synchronized void writeObject(ObjectOutputStream s)
throws IOException
{

View file

@ -299,6 +299,7 @@ class InetAddress implements java.io.Serializable {
private transient String canonicalHostName = null;
/** use serialVersionUID from JDK 1.0.2 for interoperability */
@java.io.Serial
private static final long serialVersionUID = 3286316764910316507L;
/*
@ -353,6 +354,7 @@ class InetAddress implements java.io.Serializable {
* @throws ObjectStreamException if a new object replacing this
* object could not be created
*/
@java.io.Serial
private Object readResolve() throws ObjectStreamException {
// will replace the deserialized 'this' object
return new Inet4Address(holder().getHostName(), holder().getAddress());
@ -1687,6 +1689,7 @@ class InetAddress implements java.io.Serializable {
return (InetAddressImpl) impl;
}
@java.io.Serial
private void readObjectNoData () {
if (getClass().getClassLoader() != null) {
throw new SecurityException ("invalid address type");
@ -1698,6 +1701,7 @@ class InetAddress implements java.io.Serializable {
private static final long FIELDS_OFFSET
= UNSAFE.objectFieldOffset(InetAddress.class, "holder");
@java.io.Serial
private void readObject (ObjectInputStream s) throws
IOException, ClassNotFoundException {
if (getClass().getClassLoader() != null) {
@ -1721,12 +1725,14 @@ class InetAddress implements java.io.Serializable {
* @serialField address int
* @serialField family int
*/
@java.io.Serial
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("hostName", String.class),
new ObjectStreamField("address", int.class),
new ObjectStreamField("family", int.class),
};
@java.io.Serial
private void writeObject (ObjectOutputStream s) throws
IOException {
if (getClass().getClassLoader() != null) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -136,6 +136,7 @@ public class InetSocketAddress
private final transient InetSocketAddressHolder holder;
@java.io.Serial
private static final long serialVersionUID = 5076001401234631237L;
private static int checkPort(int port) {
@ -259,11 +260,13 @@ public class InetSocketAddress
* @serialField addr InetAddress
* @serialField port int
*/
@java.io.Serial
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("hostname", String.class),
new ObjectStreamField("addr", InetAddress.class),
new ObjectStreamField("port", int.class)};
@java.io.Serial
private void writeObject(ObjectOutputStream out)
throws IOException
{
@ -275,6 +278,7 @@ public class InetSocketAddress
out.writeFields();
}
@java.io.Serial
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
@ -296,6 +300,7 @@ public class InetSocketAddress
UNSAFE.putReference(this, FIELDS_OFFSET, h);
}
@java.io.Serial
private void readObjectNoData()
throws ObjectStreamException
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,6 +36,7 @@ import java.io.IOException;
* @since 1.0
*/
public class MalformedURLException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -182787522200415866L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -175,6 +175,7 @@ import java.util.StringTokenizer;
*/
public final class NetPermission extends BasicPermission {
@java.io.Serial
private static final long serialVersionUID = -8343910153355041693L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ package java.net;
* @since 1.1
*/
public class NoRouteToHostException extends SocketException {
@java.io.Serial
private static final long serialVersionUID = -1897550894873493790L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@ package java.net;
*/
public class PortUnreachableException extends SocketException {
@java.io.Serial
private static final long serialVersionUID = 8462541992376507323L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,6 +36,7 @@ import java.io.IOException;
*/
public
class ProtocolException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -6098449442062388080L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,6 +40,7 @@ package java.net;
*/
public abstract class SocketAddress implements java.io.Serializable {
@java.io.Serial
static final long serialVersionUID = 5215720748342549866L;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,6 +35,7 @@ import java.io.IOException;
*/
public
class SocketException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -5935874303556886934L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -150,6 +150,7 @@ import sun.security.util.Debug;
public final class SocketPermission extends Permission
implements java.io.Serializable
{
@java.io.Serial
private static final long serialVersionUID = -7204263841984476862L;
/**
@ -1186,6 +1187,7 @@ public final class SocketPermission extends Permission
* to a stream. The actions are serialized, and the superclass
* takes care of the name.
*/
@java.io.Serial
private synchronized void writeObject(java.io.ObjectOutputStream s)
throws IOException
{
@ -1200,6 +1202,7 @@ public final class SocketPermission extends Permission
* readObject is called to restore the state of the SocketPermission from
* a stream.
*/
@java.io.Serial
private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException
{
@ -1448,6 +1451,7 @@ final class SocketPermissionCollection extends PermissionCollection
return (Enumeration)Collections.enumeration(perms.values());
}
@java.io.Serial
private static final long serialVersionUID = 2787186408602843674L;
// Need to maintain serialization interoperability with earlier releases,
@ -1463,6 +1467,7 @@ final class SocketPermissionCollection extends PermissionCollection
* @serialField permissions java.util.Vector
* A list of the SocketPermissions for this set.
*/
@java.io.Serial
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("permissions", Vector.class),
};
@ -1474,6 +1479,7 @@ final class SocketPermissionCollection extends PermissionCollection
* Writes the contents of the perms field out as a Vector for
* serialization compatibility with earlier releases.
*/
@java.io.Serial
private void writeObject(ObjectOutputStream out) throws IOException {
// Don't call out.defaultWriteObject()
@ -1488,6 +1494,7 @@ final class SocketPermissionCollection extends PermissionCollection
/*
* Reads in a Vector of SocketPermissions and saves them in the perms field.
*/
@java.io.Serial
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,6 +32,7 @@ package java.net;
*/
public class SocketTimeoutException extends java.io.InterruptedIOException {
@java.io.Serial
private static final long serialVersionUID = -8846654841826352300L;
/**

View file

@ -503,7 +503,7 @@ public final class URI
// Note: Comments containing the word "ASSERT" indicate places where a
// throw of an InternalError should be replaced by an appropriate assertion
// statement once asserts are enabled in the build.
@java.io.Serial
static final long serialVersionUID = -6052424284110960213L;
@ -1777,6 +1777,7 @@ public final class URI
* @param os The object-output stream to which this object
* is to be written
*/
@java.io.Serial
private void writeObject(ObjectOutputStream os)
throws IOException
{
@ -1794,6 +1795,7 @@ public final class URI
* @param is The object-input stream from which this object
* is being read
*/
@java.io.Serial
private void readObject(ObjectInputStream is)
throws ClassNotFoundException, IOException
{

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,6 +38,7 @@ package java.net;
public class URISyntaxException
extends Exception
{
@java.io.Serial
private static final long serialVersionUID = 2137979680897488891L;
private String input;

View file

@ -175,6 +175,7 @@ import sun.security.action.GetPropertyAction;
public final class URL implements java.io.Serializable {
static final String BUILTIN_HANDLERS_PREFIX = "sun.net.www.protocol";
@java.io.Serial
static final long serialVersionUID = -7627629688361524110L;
/**
@ -1489,6 +1490,7 @@ public final class URL implements java.io.Serializable {
* @serialField hashCode int
*
*/
@java.io.Serial
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("protocol", String.class),
new ObjectStreamField("host", String.class),
@ -1508,6 +1510,7 @@ public final class URL implements java.io.Serializable {
* the protocol variable returns a valid URLStreamHandler and
* throw an IOException if it does not.
*/
@java.io.Serial
private synchronized void writeObject(java.io.ObjectOutputStream s)
throws IOException
{
@ -1519,6 +1522,7 @@ public final class URL implements java.io.Serializable {
* stream. It reads the components of the URL and finds the local
* stream handler.
*/
@java.io.Serial
private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException {
GetField gf = s.readFields();
@ -1550,7 +1554,7 @@ public final class URL implements java.io.Serializable {
* @throws ObjectStreamException if a new object replacing this
* object could not be created
*/
@java.io.Serial
private Object readResolve() throws ObjectStreamException {
URLStreamHandler handler = null;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -151,6 +151,7 @@ import java.security.Permission;
*/
public final class URLPermission extends Permission {
@java.io.Serial
private static final long serialVersionUID = -2702463814894478682L;
private transient String scheme;
@ -505,6 +506,7 @@ public final class URLPermission extends Permission {
/**
* restore the state of this object from stream
*/
@java.io.Serial
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = s.readFields();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,6 +35,7 @@ import java.io.IOException;
*/
public
class UnknownHostException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -4639126076052875403L;
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ import java.io.IOException;
* @since 1.0
*/
public class UnknownServiceException extends IOException {
@java.io.Serial
private static final long serialVersionUID = -4169033248853639508L;
/**