Skip to content

Commit 1769596

Browse files
mcpowerswangweij
authored andcommitted
8285263: Minor cleanup could be done in java.security
Reviewed-by: weijun
1 parent b97a4f6 commit 1769596

File tree

94 files changed

+478
-599
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+478
-599
lines changed

src/java.base/share/classes/java/security/AlgorithmConstraints.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, 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
@@ -61,12 +61,12 @@ public interface AlgorithmConstraints {
6161
* parameters
6262
*
6363
* @return true if the algorithm is permitted and can be used for all
64-
* of the specified cryptographic primitives
64+
* the specified cryptographic primitives
6565
*
6666
* @throws IllegalArgumentException if primitives or algorithm is null
6767
* or empty
6868
*/
69-
public boolean permits(Set<CryptoPrimitive> primitives,
69+
boolean permits(Set<CryptoPrimitive> primitives,
7070
String algorithm, AlgorithmParameters parameters);
7171

7272
/**
@@ -78,13 +78,13 @@ public boolean permits(Set<CryptoPrimitive> primitives,
7878
* @param primitives a set of cryptographic primitives
7979
* @param key the key
8080
*
81-
* @return true if the key can be used for all of the specified
81+
* @return true if the key can be used for all the specified
8282
* cryptographic primitives
8383
*
8484
* @throws IllegalArgumentException if primitives is null or empty,
8585
* or the key is null
8686
*/
87-
public boolean permits(Set<CryptoPrimitive> primitives, Key key);
87+
boolean permits(Set<CryptoPrimitive> primitives, Key key);
8888

8989
/**
9090
* Determines whether an algorithm and the corresponding key are granted
@@ -96,13 +96,13 @@ public boolean permits(Set<CryptoPrimitive> primitives,
9696
* @param parameters the algorithm parameters, or null if no additional
9797
* parameters
9898
*
99-
* @return true if the key and the algorithm can be used for all of the
99+
* @return true if the key and the algorithm can be used for all the
100100
* specified cryptographic primitives
101101
*
102102
* @throws IllegalArgumentException if primitives or algorithm is null
103103
* or empty, or the key is null
104104
*/
105-
public boolean permits(Set<CryptoPrimitive> primitives,
105+
boolean permits(Set<CryptoPrimitive> primitives,
106106
String algorithm, Key key, AlgorithmParameters parameters);
107107

108108
}

src/java.base/share/classes/java/security/AlgorithmParameterGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -99,13 +99,13 @@
9999
public class AlgorithmParameterGenerator {
100100

101101
// The provider
102-
private Provider provider;
102+
private final Provider provider;
103103

104104
// The provider implementation (delegate)
105-
private AlgorithmParameterGeneratorSpi paramGenSpi;
105+
private final AlgorithmParameterGeneratorSpi paramGenSpi;
106106

107107
// The algorithm
108-
private String algorithm;
108+
private final String algorithm;
109109

110110
/**
111111
* Creates an AlgorithmParameterGenerator object.
@@ -150,7 +150,7 @@ public final String getAlgorithm() {
150150
* {@code jdk.security.provider.preferred}
151151
* {@link Security#getProperty(String) Security} property to determine
152152
* the preferred provider order for the specified algorithm. This
153-
* may be different than the order of providers returned by
153+
* may be different from the order of providers returned by
154154
* {@link Security#getProviders() Security.getProviders()}.
155155
*
156156
* @param algorithm the name of the algorithm this

src/java.base/share/classes/java/security/AlgorithmParameters.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -75,13 +75,13 @@
7575
public class AlgorithmParameters {
7676

7777
// The provider
78-
private Provider provider;
78+
private final Provider provider;
7979

8080
// The provider implementation (delegate)
81-
private AlgorithmParametersSpi paramSpi;
81+
private final AlgorithmParametersSpi paramSpi;
8282

8383
// The algorithm
84-
private String algorithm;
84+
private final String algorithm;
8585

8686
// Has this object been initialized?
8787
private boolean initialized = false;
@@ -131,7 +131,7 @@ public final String getAlgorithm() {
131131
* {@code jdk.security.provider.preferred}
132132
* {@link Security#getProperty(String) Security} property to determine
133133
* the preferred provider order for the specified algorithm. This
134-
* may be different than the order of providers returned by
134+
* may be different from the order of providers returned by
135135
* {@link Security#getProviders() Security.getProviders()}.
136136
*
137137
* @param algorithm the name of the algorithm requested.
@@ -342,7 +342,7 @@ public final void init(byte[] params, String format) throws IOException {
342342
* parameters should be returned in an instance of the
343343
* {@code DSAParameterSpec} class.
344344
*
345-
* @param <T> the type of the parameter specification to be returrned
345+
* @param <T> the type of the parameter specification to be returned
346346
* @param paramSpec the specification class in which
347347
* the parameters should be returned.
348348
*
@@ -356,7 +356,7 @@ public final void init(byte[] params, String format) throws IOException {
356356
T getParameterSpec(Class<T> paramSpec)
357357
throws InvalidParameterSpecException
358358
{
359-
if (this.initialized == false) {
359+
if (!this.initialized) {
360360
throw new InvalidParameterSpecException("not initialized");
361361
}
362362
return paramSpi.engineGetParameterSpec(paramSpec);
@@ -374,7 +374,7 @@ T getParameterSpec(Class<T> paramSpec)
374374
*/
375375
public final byte[] getEncoded() throws IOException
376376
{
377-
if (this.initialized == false) {
377+
if (!this.initialized) {
378378
throw new IOException("not initialized");
379379
}
380380
return paramSpi.engineGetEncoded();
@@ -396,7 +396,7 @@ public final byte[] getEncoded() throws IOException
396396
*/
397397
public final byte[] getEncoded(String format) throws IOException
398398
{
399-
if (this.initialized == false) {
399+
if (!this.initialized) {
400400
throw new IOException("not initialized");
401401
}
402402
return paramSpi.engineGetEncoded(format);
@@ -409,7 +409,7 @@ public final byte[] getEncoded(String format) throws IOException
409409
* parameter object has not been initialized.
410410
*/
411411
public final String toString() {
412-
if (this.initialized == false) {
412+
if (!this.initialized) {
413413
return null;
414414
}
415415
return paramSpi.engineToString();

src/java.base/share/classes/java/security/AllPermission.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2022, 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
@@ -25,12 +25,10 @@
2525

2626
package java.security;
2727

28-
import java.security.*;
29-
import java.util.Enumeration;
30-
import java.util.Hashtable;
31-
import java.util.StringTokenizer;
3228
import sun.security.util.SecurityConstants;
3329

30+
import java.util.Enumeration;
31+
3432
/**
3533
* The AllPermission is a permission that implies all other permissions.
3634
* <p>

src/java.base/share/classes/java/security/BasicPermission.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -40,7 +40,7 @@
4040
* <P>
4141
* The name for a BasicPermission is the name of the given permission
4242
* (for example, "exit",
43-
* "setFactory", "print.queueJob", etc). The naming
43+
* "setFactory", "print.queueJob", etc.). The naming
4444
* convention follows the hierarchical property naming convention.
4545
* An asterisk may appear by itself, or if immediately preceded by a "."
4646
* may appear at the end of the name, to signify a wildcard match.

src/java.base/share/classes/java/security/CodeSigner.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, 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
@@ -46,14 +46,14 @@ public final class CodeSigner implements Serializable {
4646
*
4747
* @serial
4848
*/
49-
private CertPath signerCertPath;
49+
private final CertPath signerCertPath;
5050

5151
/**
5252
* The signature timestamp.
5353
*
5454
* @serial
5555
*/
56-
private Timestamp timestamp;
56+
private final Timestamp timestamp;
5757

5858
/*
5959
* Hash code for this code signer.
@@ -126,7 +126,7 @@ public int hashCode() {
126126
* @return true if the objects are considered equal, false otherwise.
127127
*/
128128
public boolean equals(Object obj) {
129-
if (obj == null || (!(obj instanceof CodeSigner that))) {
129+
if ((!(obj instanceof CodeSigner that))) {
130130
return false;
131131
}
132132

@@ -139,8 +139,7 @@ public boolean equals(Object obj) {
139139
return false;
140140
}
141141
} else {
142-
if (thatTimestamp == null ||
143-
(! timestamp.equals(thatTimestamp))) {
142+
if ((!timestamp.equals(thatTimestamp))) {
144143
return false;
145144
}
146145
}

src/java.base/share/classes/java/security/CodeSource.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -80,7 +80,7 @@ public class CodeSource implements java.io.Serializable {
8080

8181
/**
8282
* A String form of the URL for use as a key in HashMaps/Sets. The String
83-
* form should be behave in the same manner as the URL when compared for
83+
* form should behave in the same manner as the URL when compared for
8484
* equality in a HashMap/Set, except that no nameservice lookup is done
8585
* on the hostname (only string comparison), and the fragment is not
8686
* considered.
@@ -211,7 +211,7 @@ public final java.security.cert.Certificate[] getCertificates() {
211211
signers[i].getSignerCertPath().getCertificates());
212212
}
213213
certs = certChains.toArray(
214-
new java.security.cert.Certificate[certChains.size()]);
214+
new java.security.cert.Certificate[0]);
215215
return certs.clone();
216216

217217
} else {
@@ -330,7 +330,7 @@ public boolean implies(CodeSource codesource)
330330
*
331331
* @param that the CodeSource to check against.
332332
* @param strict if true then a strict equality match is performed.
333-
* Otherwise a subset match is performed.
333+
* Otherwise, a subset match is performed.
334334
*/
335335
boolean matchCerts(CodeSource that, boolean strict)
336336
{
@@ -461,9 +461,7 @@ private boolean matchLocation(CodeSource that) {
461461
if (that.sp == null) {
462462
that.sp = new SocketPermission(thatHost, "resolve");
463463
}
464-
if (!this.sp.implies(that.sp)) {
465-
return false;
466-
}
464+
return this.sp.implies(that.sp);
467465
}
468466
}
469467
// everything matches
@@ -570,7 +568,7 @@ private void readObject(java.io.ObjectInputStream ois)
570568
// we know of 3 different cert types: X.509, PGP, SDSI, which
571569
// could all be present in the stream at the same time
572570
cfs = new Hashtable<>(3);
573-
certList = new ArrayList<>(size > 20 ? 20 : size);
571+
certList = new ArrayList<>(Math.min(size, 20));
574572
} else if (size < 0) {
575573
throw new IOException("size cannot be negative");
576574
}
@@ -665,7 +663,7 @@ private CodeSigner[] convertCertArrayToSignerArray(
665663
if (signers.isEmpty()) {
666664
return null;
667665
} else {
668-
return signers.toArray(new CodeSigner[signers.size()]);
666+
return signers.toArray(new CodeSigner[0]);
669667
}
670668

671669
} catch (CertificateException e) {

src/java.base/share/classes/java/security/DigestInputStream.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, 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
@@ -25,12 +25,9 @@
2525

2626
package java.security;
2727

28+
import java.io.FilterInputStream;
2829
import java.io.IOException;
29-
import java.io.EOFException;
3030
import java.io.InputStream;
31-
import java.io.FilterInputStream;
32-
import java.io.PrintStream;
33-
import java.io.ByteArrayInputStream;
3431

3532
/**
3633
* A transparent stream that updates the associated message digest using

src/java.base/share/classes/java/security/DigestOutputStream.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, 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
@@ -25,12 +25,9 @@
2525

2626
package java.security;
2727

28+
import java.io.FilterOutputStream;
2829
import java.io.IOException;
29-
import java.io.EOFException;
3030
import java.io.OutputStream;
31-
import java.io.FilterOutputStream;
32-
import java.io.PrintStream;
33-
import java.io.ByteArrayOutputStream;
3431

3532
/**
3633
* A transparent stream that updates the associated message digest using

src/java.base/share/classes/java/security/DomainLoadStoreParameter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2022, 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
@@ -49,7 +49,7 @@
4949
* and {@code property} is a key/value pairing. The key and value are
5050
* separated by an 'equals' symbol and the value is enclosed in double
5151
* quotes. A property value may be either a printable string or a binary
52-
* string of colon-separated pairs of hexadecimal digits. Multi-valued
52+
* string of colon-separated pairs of hexadecimal digits. Multivalued
5353
* properties are represented as a comma-separated list of values,
5454
* enclosed in square brackets.
5555
* See {@link Arrays#toString(java.lang.Object[])}.

0 commit comments

Comments
 (0)