Skip to content

Commit c3bc4fc

Browse files
minborgValerie Peng
authored andcommitted
8297505: Declare fields in some sun.security.pkcs11 classes as final
Reviewed-by: valeriep
1 parent c7aca73 commit c3bc4fc

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public List<String> run() {
8888
private static final boolean DEBUG = false;
8989

9090
// file name containing this configuration
91-
private String filename;
91+
private final String filename;
9292

9393
// Reader and StringTokenizer used during parsing
9494
private Reader reader;

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ private enum Transformation {
110110
private SecureRandom random = JCAUtil.getSecureRandom();
111111

112112
// dataBuffer is cleared upon doFinal calls
113-
private ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream();
113+
private final ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream();
114114
// aadBuffer is cleared upon successful init calls
115-
private ByteArrayOutputStream aadBuffer = new ByteArrayOutputStream();
115+
private final ByteArrayOutputStream aadBuffer = new ByteArrayOutputStream();
116116
private boolean updateCalled = false;
117117

118118
private boolean requireReinit = false;

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ final class NativeKeyHolder {
13211321
private long keyID;
13221322

13231323
// phantom reference notification clean up for session keys
1324-
private SessionKeyRef ref;
1324+
private final SessionKeyRef ref;
13251325

13261326
private int refCount;
13271327

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyWrapCipher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private enum KeyWrapType {
117117
private SecureRandom random = JCAUtil.getSecureRandom();
118118

119119
// dataBuffer for storing enc/dec data; cleared upon doFinal calls
120-
private ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream();
120+
private final ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream();
121121

122122
P11KeyWrapCipher(Token token, String algorithm, long mechanism)
123123
throws PKCS11Exception, NoSuchAlgorithmException {

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSACipher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ final class ConstructKeys {
625625
*
626626
* @return a public key constructed from the encodedKey.
627627
*/
628-
private static final PublicKey constructPublicKey(byte[] encodedKey,
628+
private static PublicKey constructPublicKey(byte[] encodedKey,
629629
String encodedKeyAlgorithm)
630630
throws InvalidKeyException, NoSuchAlgorithmException {
631631
try {
@@ -652,7 +652,7 @@ private static final PublicKey constructPublicKey(byte[] encodedKey,
652652
*
653653
* @return a private key constructed from the encodedKey.
654654
*/
655-
private static final PrivateKey constructPrivateKey(byte[] encodedKey,
655+
private static PrivateKey constructPrivateKey(byte[] encodedKey,
656656
String encodedKeyAlgorithm) throws InvalidKeyException,
657657
NoSuchAlgorithmException {
658658
try {
@@ -679,12 +679,12 @@ private static final PrivateKey constructPrivateKey(byte[] encodedKey,
679679
*
680680
* @return a secret key constructed from the encodedKey.
681681
*/
682-
private static final SecretKey constructSecretKey(byte[] encodedKey,
682+
private static SecretKey constructSecretKey(byte[] encodedKey,
683683
String encodedKeyAlgorithm) {
684684
return new SecretKeySpec(encodedKey, encodedKeyAlgorithm);
685685
}
686686

687-
static final Key constructKey(byte[] encoding, String keyAlgorithm,
687+
static Key constructKey(byte[] encoding, String keyAlgorithm,
688688
int keyType) throws InvalidKeyException, NoSuchAlgorithmException {
689689
return switch (keyType) {
690690
case Cipher.SECRET_KEY -> constructSecretKey(encoding, keyAlgorithm);

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class P11TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi {
5555
private final String algorithm;
5656

5757
// mechanism id
58-
private long mechanism;
58+
private final long mechanism;
5959

6060
@SuppressWarnings("deprecation")
6161
private TlsRsaPremasterSecretParameterSpec spec;

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class P11Util {
4343
// A cleaner, shared within this module.
4444
public static final Cleaner cleaner = Cleaner.create();
4545

46-
private static Object LOCK = new Object();
46+
private static final Object LOCK = new Object();
4747

4848
private static volatile Provider sun, sunRsaSign, sunJce;
4949

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Session.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private void close(boolean checkObjCtr) {
135135
static boolean drainRefQueue() {
136136
boolean found = false;
137137
SessionRef next;
138-
while ((next = (SessionRef) SessionRef.refQueue.poll())!= null) {
138+
while ((next = (SessionRef) SessionRef.REF_QUEUE.poll())!= null) {
139139
found = true;
140140
next.dispose();
141141
}
@@ -150,24 +150,24 @@ static boolean drainRefQueue() {
150150
final class SessionRef extends PhantomReference<Session>
151151
implements Comparable<SessionRef> {
152152

153-
static ReferenceQueue<Session> refQueue = new ReferenceQueue<>();
153+
static final ReferenceQueue<Session> REF_QUEUE = new ReferenceQueue<>();
154154

155-
private static Set<SessionRef> refList =
155+
private static final Set<SessionRef> REF_LIST =
156156
Collections.synchronizedSortedSet(new TreeSet<>());
157157

158158
// handle to the native session
159-
private long id;
160-
private Token token;
159+
private final long id;
160+
private final Token token;
161161

162162
SessionRef(Session session, long id, Token token) {
163-
super(session, refQueue);
163+
super(session, REF_QUEUE);
164164
this.id = id;
165165
this.token = token;
166-
refList.add(this);
166+
REF_LIST.add(this);
167167
}
168168

169169
void dispose() {
170-
refList.remove(this);
170+
REF_LIST.remove(this);
171171
try {
172172
if (token.isPresent(id)) {
173173
token.p11.C_CloseSession(id);

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SessionManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final class SessionManager {
7878
private final int maxSessions;
7979

8080
// total number of active sessions
81-
private AtomicInteger activeSessions = new AtomicInteger();
81+
private final AtomicInteger activeSessions = new AtomicInteger();
8282

8383
// pool of available object sessions
8484
private final Pool objSessions;
@@ -88,7 +88,7 @@ final class SessionManager {
8888

8989
// maximum number of active sessions during this invocation, for debugging
9090
private int maxActiveSessions;
91-
private Object maxActiveSessionsLock;
91+
private final Object maxActiveSessionsLock;
9292

9393
// flags to use in the C_OpenSession() call
9494
private final long openSessionFlags;
@@ -112,9 +112,9 @@ final class SessionManager {
112112
this.token = token;
113113
this.objSessions = new Pool(this, true);
114114
this.opSessions = new Pool(this, false);
115-
if (debug != null) {
116-
maxActiveSessionsLock = new Object();
117-
}
115+
this.maxActiveSessionsLock = (debug != null)
116+
? new Object()
117+
: null;
118118
}
119119

120120
// returns whether only a fairly low number of sessions are

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Token.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @author Andreas Sterbenz
4747
* @since 1.5
4848
*/
49-
class Token implements Serializable {
49+
final class Token implements Serializable {
5050

5151
// need to be serializable to allow SecureRandom to be serialized
5252
@Serial

0 commit comments

Comments
 (0)