Skip to content

Commit b72de3c

Browse files
committedJan 11, 2021
8259385: Cleanup unused assignment
Reviewed-by: attila
1 parent 9154f64 commit b72de3c

18 files changed

+70
-79
lines changed
 

‎src/java.base/share/classes/sun/security/ssl/CertStatusExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ private CTCertStatusResponseProducer() {
11031103
public byte[] produce(ConnectionContext context,
11041104
HandshakeMessage message) throws IOException {
11051105
ServerHandshakeContext shc = (ServerHandshakeContext)context;
1106-
byte[] producedData = null;
1106+
byte[] producedData;
11071107

11081108
// Stapling needs to be active and have valid data to proceed
11091109
if (shc.stapleParams == null) {

‎src/java.base/share/classes/sun/security/ssl/CertificateStatus.java

+21-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -85,8 +85,8 @@ final class CertificateStatus {
8585
static final class CertificateStatusMessage extends HandshakeMessage {
8686

8787
final CertStatusRequestType statusType;
88-
int encodedResponsesLen = 0;
89-
int messageLength = -1;
88+
final int encodedResponsesLen;
89+
final int messageLength;
9090
final List<byte[]> encodedResponses = new ArrayList<>();
9191

9292
CertificateStatusMessage(HandshakeContext handshakeContext) {
@@ -114,6 +114,7 @@ static final class CertificateStatusMessage extends HandshakeMessage {
114114
// Walk the certificate list and add the correct encoded responses
115115
// to the encoded responses list
116116
statusType = stapleParams.statReqType;
117+
int encodedLen = 0;
117118
if (statusType == CertStatusRequestType.OCSP) {
118119
// Just worry about the first cert in the chain
119120
byte[] resp = stapleParams.responseMap.get(certChain[0]);
@@ -124,22 +125,23 @@ static final class CertificateStatusMessage extends HandshakeMessage {
124125
resp = new byte[0];
125126
}
126127
encodedResponses.add(resp);
127-
encodedResponsesLen += resp.length + 3;
128+
encodedLen += resp.length + 3;
128129
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
129130
for (X509Certificate cert : certChain) {
130131
byte[] resp = stapleParams.responseMap.get(cert);
131132
if (resp == null) {
132133
resp = new byte[0];
133134
}
134135
encodedResponses.add(resp);
135-
encodedResponsesLen += resp.length + 3;
136+
encodedLen += resp.length + 3;
136137
}
137138
} else {
138139
throw new IllegalArgumentException(
139140
"Unsupported StatusResponseType: " + statusType);
140141
}
141142

142-
messageLength = messageLength();
143+
encodedResponsesLen = encodedLen;
144+
messageLength = messageLength(statusType, encodedResponsesLen);
143145
}
144146

145147
CertificateStatusMessage(HandshakeContext handshakeContext,
@@ -182,7 +184,18 @@ static final class CertificateStatusMessage extends HandshakeMessage {
182184
Alert.HANDSHAKE_FAILURE,
183185
"Unsupported StatusResponseType: " + statusType);
184186
}
185-
messageLength = messageLength();
187+
messageLength = messageLength(statusType, encodedResponsesLen);
188+
}
189+
190+
private static int messageLength(
191+
CertStatusRequestType statusType, int encodedResponsesLen) {
192+
if (statusType == CertStatusRequestType.OCSP) {
193+
return 1 + encodedResponsesLen;
194+
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
195+
return 4 + encodedResponsesLen;
196+
}
197+
198+
return -1;
186199
}
187200

188201
@Override
@@ -192,17 +205,6 @@ public SSLHandshake handshakeType() {
192205

193206
@Override
194207
public int messageLength() {
195-
int len = 1;
196-
197-
if (messageLength == -1) {
198-
if (statusType == CertStatusRequestType.OCSP) {
199-
len += encodedResponsesLen;
200-
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
201-
len += 3 + encodedResponsesLen;
202-
}
203-
messageLength = len;
204-
}
205-
206208
return messageLength;
207209
}
208210

@@ -214,11 +216,7 @@ public void send(HandshakeOutStream s) throws IOException {
214216
} else if (statusType == CertStatusRequestType.OCSP_MULTI) {
215217
s.putInt24(encodedResponsesLen);
216218
for (byte[] respBytes : encodedResponses) {
217-
if (respBytes != null) {
218-
s.putBytes24(respBytes);
219-
} else {
220-
s.putBytes24(null);
221-
}
219+
s.putBytes24(respBytes);
222220
}
223221
} else {
224222
// It is highly unlikely that we will fall into this section

‎src/java.base/share/classes/sun/security/ssl/CertificateVerify.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -74,15 +74,15 @@ static final class S30CertificateVerifyMessage extends HandshakeMessage {
7474

7575
// This happens in client side only.
7676
ClientHandshakeContext chc = (ClientHandshakeContext)context;
77-
byte[] temproary = null;
77+
byte[] temporary;
7878
String algorithm = x509Possession.popPrivateKey.getAlgorithm();
7979
try {
8080
Signature signer =
8181
getSignature(algorithm, x509Possession.popPrivateKey);
8282
byte[] hashes = chc.handshakeHash.digest(algorithm,
8383
chc.handshakeSession.getMasterSecret());
8484
signer.update(hashes);
85-
temproary = signer.sign();
85+
temporary = signer.sign();
8686
} catch (NoSuchAlgorithmException nsae) {
8787
throw chc.conContext.fatal(Alert.INTERNAL_ERROR,
8888
"Unsupported signature algorithm (" + algorithm +
@@ -92,7 +92,7 @@ static final class S30CertificateVerifyMessage extends HandshakeMessage {
9292
"Cannot produce CertificateVerify signature", gse);
9393
}
9494

95-
this.signature = temproary;
95+
this.signature = temporary;
9696
}
9797

9898
S30CertificateVerifyMessage(HandshakeContext context,
@@ -194,7 +194,7 @@ public String toString() {
194194
*/
195195
private static Signature getSignature(String algorithm,
196196
Key key) throws GeneralSecurityException {
197-
Signature signer = null;
197+
Signature signer;
198198
switch (algorithm) {
199199
case "RSA":
200200
signer = Signature.getInstance(JsseJce.SIGNATURE_RAWRSA);
@@ -330,14 +330,14 @@ static final class T10CertificateVerifyMessage extends HandshakeMessage {
330330

331331
// This happens in client side only.
332332
ClientHandshakeContext chc = (ClientHandshakeContext)context;
333-
byte[] temproary = null;
333+
byte[] temporary;
334334
String algorithm = x509Possession.popPrivateKey.getAlgorithm();
335335
try {
336336
Signature signer =
337337
getSignature(algorithm, x509Possession.popPrivateKey);
338338
byte[] hashes = chc.handshakeHash.digest(algorithm);
339339
signer.update(hashes);
340-
temproary = signer.sign();
340+
temporary = signer.sign();
341341
} catch (NoSuchAlgorithmException nsae) {
342342
throw chc.conContext.fatal(Alert.INTERNAL_ERROR,
343343
"Unsupported signature algorithm (" + algorithm +
@@ -347,7 +347,7 @@ static final class T10CertificateVerifyMessage extends HandshakeMessage {
347347
"Cannot produce CertificateVerify signature", gse);
348348
}
349349

350-
this.signature = temproary;
350+
this.signature = temporary;
351351
}
352352

353353
T10CertificateVerifyMessage(HandshakeContext context,
@@ -448,7 +448,7 @@ public String toString() {
448448
*/
449449
private static Signature getSignature(String algorithm,
450450
Key key) throws GeneralSecurityException {
451-
Signature signer = null;
451+
Signature signer;
452452
switch (algorithm) {
453453
case "RSA":
454454
signer = Signature.getInstance(JsseJce.SIGNATURE_RAWRSA);
@@ -605,17 +605,17 @@ static final class T12CertificateVerifyMessage extends HandshakeMessage {
605605
}
606606

607607
this.signatureScheme = schemeAndSigner.getKey();
608-
byte[] temproary = null;
608+
byte[] temporary;
609609
try {
610610
Signature signer = schemeAndSigner.getValue();
611611
signer.update(chc.handshakeHash.archived());
612-
temproary = signer.sign();
612+
temporary = signer.sign();
613613
} catch (SignatureException ikse) {
614614
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
615615
"Cannot produce CertificateVerify signature", ikse);
616616
}
617617

618-
this.signature = temproary;
618+
this.signature = temporary;
619619
}
620620

621621
T12CertificateVerifyMessage(HandshakeContext handshakeContext,
@@ -930,17 +930,17 @@ static final class T13CertificateVerifyMessage extends HandshakeMessage {
930930
serverSignHead.length, hashValue.length);
931931
}
932932

933-
byte[] temproary = null;
933+
byte[] temporary;
934934
try {
935935
Signature signer = schemeAndSigner.getValue();
936936
signer.update(contentCovered);
937-
temproary = signer.sign();
937+
temporary = signer.sign();
938938
} catch (SignatureException ikse) {
939939
throw context.conContext.fatal(Alert.HANDSHAKE_FAILURE,
940940
"Cannot produce CertificateVerify signature", ikse);
941941
}
942942

943-
this.signature = temproary;
943+
this.signature = temporary;
944944
}
945945

946946
T13CertificateVerifyMessage(HandshakeContext context,

‎src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class DHServerKeyExchangeMessage extends HandshakeMessage {
123123
} else {
124124
useExplicitSigAlgorithm =
125125
shc.negotiatedProtocol.useTLS12PlusSpec();
126-
Signature signer = null;
126+
Signature signer;
127127
if (useExplicitSigAlgorithm) {
128128
Map.Entry<SignatureScheme, Signature> schemeAndSigner =
129129
SignatureScheme.getSignerOfPreferableAlgorithm(
@@ -155,7 +155,7 @@ class DHServerKeyExchangeMessage extends HandshakeMessage {
155155
}
156156
}
157157

158-
byte[] signature = null;
158+
byte[] signature;
159159
try {
160160
updateSignature(signer, shc.clientHelloRandom.randomBytes,
161161
shc.serverHelloRandom.randomBytes);
@@ -415,7 +415,7 @@ public String toString() {
415415

416416
private static Signature getSignature(String keyAlgorithm,
417417
Key key) throws NoSuchAlgorithmException, InvalidKeyException {
418-
Signature signer = null;
418+
Signature signer;
419419
switch (keyAlgorithm) {
420420
case "DSA":
421421
signer = Signature.getInstance(JsseJce.SIGNATURE_DSA);

‎src/java.base/share/classes/sun/security/ssl/DTLSInputRecord.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ private Plaintext acquireCachedMessage() throws SSLProtocolException {
11181118
bufferedFragments.remove(rFrag); // popup the fragment
11191119

11201120
ByteBuffer fragment = ByteBuffer.wrap(rFrag.fragment);
1121-
ByteBuffer plaintextFragment = null;
1121+
ByteBuffer plaintextFragment;
11221122
try {
11231123
Plaintext plaintext = readCipher.decrypt(
11241124
rFrag.contentType, fragment, rFrag.recordEnS);

‎src/java.base/share/classes/sun/security/ssl/ECDHClientKeyExchange.java

-2
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,13 @@ public byte[] produce(ConnectionContext context,
367367

368368
SSLCredentials sslCredentials = null;
369369
NamedGroup ng = null;
370-
PublicKey publicKey = null;
371370

372371
// Find a good EC/XEC credential to use, determine the
373372
// NamedGroup to use for creating Possessions/Credentials/Keys.
374373
for (SSLCredentials cd : chc.handshakeCredentials) {
375374
if (cd instanceof NamedGroupCredentials) {
376375
NamedGroupCredentials creds = (NamedGroupCredentials)cd;
377376
ng = creds.getNamedGroup();
378-
publicKey = creds.getPublicKey();
379377
sslCredentials = cd;
380378
break;
381379
}

‎src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ECDHServerKeyExchangeMessage extends HandshakeMessage {
133133
} else {
134134
useExplicitSigAlgorithm =
135135
shc.negotiatedProtocol.useTLS12PlusSpec();
136-
Signature signer = null;
136+
Signature signer;
137137
if (useExplicitSigAlgorithm) {
138138
Map.Entry<SignatureScheme, Signature> schemeAndSigner =
139139
SignatureScheme.getSignerOfPreferableAlgorithm(
@@ -165,7 +165,7 @@ class ECDHServerKeyExchangeMessage extends HandshakeMessage {
165165
}
166166
}
167167

168-
byte[] signature = null;
168+
byte[] signature;
169169
try {
170170
updateSignature(signer, shc.clientHelloRandom.randomBytes,
171171
shc.serverHelloRandom.randomBytes,
@@ -419,7 +419,7 @@ public String toString() {
419419

420420
private static Signature getSignature(String keyAlgorithm,
421421
Key key) throws NoSuchAlgorithmException, InvalidKeyException {
422-
Signature signer = null;
422+
Signature signer;
423423
switch (keyAlgorithm) {
424424
case "EC":
425425
signer = Signature.getInstance(JsseJce.SIGNATURE_ECDSA);

‎src/java.base/share/classes/sun/security/ssl/Finished.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private static final class FinishedMessage extends HandshakeMessage {
7979
VerifyDataScheme vds =
8080
VerifyDataScheme.valueOf(context.negotiatedProtocol);
8181

82-
byte[] vd = null;
82+
byte[] vd;
8383
try {
8484
vd = vds.createVerifyData(context, false);
8585
} catch (IOException ioe) {

‎src/java.base/share/classes/sun/security/ssl/OutputRecord.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ private long t13Encrypt(
486486
}
487487

488488
// use the right TLSCiphertext.opaque_type and legacy_record_version
489-
ProtocolVersion pv = protocolVersion;
489+
ProtocolVersion pv;
490490
if (!encCipher.isNullCipher()) {
491491
pv = ProtocolVersion.TLS12;
492492
contentType = ContentType.APPLICATION_DATA.id;

‎src/java.base/share/classes/sun/security/ssl/RSAKeyExchange.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, 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
@@ -135,7 +135,7 @@ static RSAPremasterSecret decode(ServerHandshakeContext shc,
135135
byte[] encrypted) throws GeneralSecurityException {
136136

137137
byte[] encoded = null;
138-
boolean needFailover = false;
138+
boolean needFailover;
139139
Cipher cipher = Cipher.getInstance(JsseJce.CIPHER_RSA_PKCS1);
140140
try {
141141
// Try UNWRAP_MODE mode firstly.

‎src/java.base/share/classes/sun/security/ssl/RSAServerKeyExchange.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, 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
@@ -83,7 +83,7 @@ private RSAServerKeyExchangeMessage(HandshakeContext handshakeContext,
8383
RSAPublicKeySpec spec = JsseJce.getRSAPublicKeySpec(publicKey);
8484
this.modulus = Utilities.toByteArray(spec.getModulus());
8585
this.exponent = Utilities.toByteArray(spec.getPublicExponent());
86-
byte[] signature = null;
86+
byte[] signature;
8787
try {
8888
Signature signer = RSASignature.getInstance();
8989
signer.initSign(x509Possession.popPrivateKey,

0 commit comments

Comments
 (0)
Please sign in to comment.