Skip to content

Commit a44b45f

Browse files
committed
4337793: Mark non-serializable fields of java.security.cert.Certificate and CertPath
Reviewed-by: valeriep, rriggs
1 parent b3a62b4 commit a44b45f

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/java.base/share/classes/java/security/cert/CertPath.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public abstract class CertPath implements Serializable {
123123
private static final long serialVersionUID = 6068470306649138683L;
124124

125125
/** The type of certificates in this chain. */
126-
private String type;
126+
private final transient String type;
127127

128128
/**
129129
* Creates a {@code CertPath} of the specified type.
@@ -270,9 +270,11 @@ public abstract byte[] getEncoded(String encoding)
270270

271271
/**
272272
* Replaces the {@code CertPath} to be serialized with a
273-
* {@code CertPathRep} object.
273+
* {@link CertPathRep CertPathRep} object containing the
274+
* {@code Certificate} type and encoded bytes of the {@code CertPath}.
274275
*
275-
* @return the {@code CertPathRep} to be serialized
276+
* @return a {@code CertPathRep} containing the {@code Certificate} type
277+
* and encoded bytes of the {@code CertPath}
276278
*
277279
* @throws ObjectStreamException if a {@code CertPathRep} object
278280
* representing this certification path could not be created
@@ -299,16 +301,16 @@ protected static class CertPathRep implements Serializable {
299301
@java.io.Serial
300302
private static final long serialVersionUID = 3015633072427920915L;
301303

302-
/** The Certificate type */
304+
/** The type of {@code Certificate}s in the {@code CertPath}. */
303305
private String type;
304-
/** The encoded form of the cert path */
306+
/** The encoded form of the {@code CertPath}. */
305307
private byte[] data;
306308

307309
/**
308310
* Creates a {@code CertPathRep} with the specified
309311
* type and encoded form of a certification path.
310312
*
311-
* @param type the standard name of a {@code CertPath} type
313+
* @param type the standard name of a {@code Certificate} type
312314
* @param data the encoded form of the certification path
313315
*/
314316
protected CertPathRep(String type, byte[] data) {
@@ -317,11 +319,12 @@ protected CertPathRep(String type, byte[] data) {
317319
}
318320

319321
/**
320-
* Returns a {@code CertPath} constructed from the type and data.
322+
* Returns a {@code CertPath} constructed from the type and data of
323+
* this {@code CertPathRep}.
321324
*
322325
* @return the resolved {@code CertPath} object
323326
*
324-
* @throws ObjectStreamException if a {@code CertPath} could not
327+
* @throws ObjectStreamException if a {@code CertPath} object could not
325328
* be constructed
326329
*/
327330
@java.io.Serial

src/java.base/share/classes/java/security/cert/Certificate.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public abstract class Certificate implements java.io.Serializable {
6666
private static final long serialVersionUID = -3585440601605666277L;
6767

6868
/** The certificate type. */
69-
private final String type;
69+
private final transient String type;
7070

7171
/** The hash code for the certificate. */
72-
private int hash = -1; // Default to -1
72+
private transient int hash = -1; // Default to -1
7373

7474
/**
7575
* Creates a certificate of the specified type.
@@ -236,7 +236,7 @@ public void verify(PublicKey key, Provider sigProvider)
236236
public abstract PublicKey getPublicKey();
237237

238238
/**
239-
* Alternate Certificate class for serialization.
239+
* Alternate {@code Certificate} class for serialization.
240240
* @since 1.3
241241
*/
242242
protected static class CertificateRep implements java.io.Serializable {
@@ -251,24 +251,25 @@ protected static class CertificateRep implements java.io.Serializable {
251251
private byte[] data;
252252

253253
/**
254-
* Construct the alternate Certificate class with the Certificate
255-
* type and Certificate encoding bytes.
254+
* Construct the alternate {@code Certificate} class with the
255+
* {@code Certificate} type and {@code Certificate} encoding bytes.
256256
*
257-
* @param type the standard name of the Certificate type.
257+
* @param type the standard name of the {@code Certificate} type.
258258
*
259-
* @param data the Certificate data.
259+
* @param data the {@code Certificate} data.
260260
*/
261261
protected CertificateRep(String type, byte[] data) {
262262
this.type = type;
263263
this.data = data;
264264
}
265265

266266
/**
267-
* Resolve the Certificate Object.
267+
* Returns a {@code Certificate} with the type and data of this
268+
* {@code CertificateRep}.
268269
*
269-
* @return the resolved Certificate Object
270+
* @return the resolved {@code Certificate} object
270271
*
271-
* @throws java.io.ObjectStreamException if the Certificate
272+
* @throws java.io.ObjectStreamException if the {@code Certificate}
272273
* could not be resolved
273274
*/
274275
@java.io.Serial
@@ -288,12 +289,15 @@ protected Object readResolve() throws java.io.ObjectStreamException {
288289
}
289290

290291
/**
291-
* Replace the Certificate to be serialized.
292+
* Replace the {@code Certificate} to be serialized with a
293+
* {@link CertificateRep CertificateRep} object containing the type and
294+
* encoded bytes of the {@code Certificate}.
292295
*
293-
* @return the alternate Certificate object to be serialized
296+
* @return a {@code CertificateRep} object containing the type and encoded
297+
* bytes of the {@code Certificate}
294298
*
295-
* @throws java.io.ObjectStreamException if a new object representing
296-
* this Certificate could not be created
299+
* @throws java.io.ObjectStreamException if a {@code CertificateRep} object
300+
* representing this {@code Certificate} could not be created
297301
* @since 1.3
298302
*/
299303
@java.io.Serial

0 commit comments

Comments
 (0)