Skip to content

Commit 4d3d599

Browse files
committed
8259223: Simplify boolean expression in the SunJSSE provider
Reviewed-by: mullan
1 parent 1b60acd commit 4d3d599

11 files changed

+35
-35
lines changed

src/java.base/share/classes/sun/security/ssl/CipherSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -890,7 +890,7 @@ private CipherSuite(int id, boolean isDefaultEnabled,
890890
this.macAlg = macAlg;
891891
this.hashAlg = hashAlg;
892892

893-
this.exportable = (cipher == null ? false : cipher.exportable);
893+
this.exportable = (cipher != null && cipher.exportable);
894894
}
895895

896896
static CipherSuite nameOf(String ciperSuiteName) {

src/java.base/share/classes/sun/security/ssl/EphemeralKeyManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -128,7 +128,7 @@ private boolean isValid() {
128128
* Return the KeyPair or null if it is invalid.
129129
*/
130130
private KeyPair getKeyPair() {
131-
if (isValid() == false) {
131+
if (!isValid()) {
132132
keyPair = null;
133133
return null;
134134
}

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

Lines changed: 2 additions & 2 deletions
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
@@ -325,7 +325,7 @@ public byte[] createVerifyData(HandshakeContext context,
325325
}
326326
}
327327

328-
// TLS 1.2
328+
// TLS 1.3
329329
private static final
330330
class T13VerifyDataGenerator implements VerifyDataGenerator {
331331
private static final byte[] hkdfLabel = "tls13 finished".getBytes();

src/java.base/share/classes/sun/security/ssl/HandshakeContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, 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
@@ -576,7 +576,7 @@ private static boolean isActivatable(CipherSuite suite,
576576

577577
retval |= groupAvailable;
578578
} else {
579-
retval |= true;
579+
retval = true;
580580
}
581581
}
582582

src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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
@@ -99,7 +99,7 @@ protected void engineInit(KeyStore ks, char[] password) throws
9999
@Override
100100
protected void engineInit(ManagerFactoryParameters params) throws
101101
InvalidAlgorithmParameterException {
102-
if (params instanceof KeyStoreBuilderParameters == false) {
102+
if (!(params instanceof KeyStoreBuilderParameters)) {
103103
throw new InvalidAlgorithmParameterException(
104104
"Parameters must be instance of KeyStoreBuilderParameters");
105105
}

src/java.base/share/classes/sun/security/ssl/ProtocolVersion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -356,23 +356,23 @@ boolean useTLS12PlusSpec() {
356356
* TLS 1.1/DTLS 1.0 or newer version.
357357
*/
358358
boolean useTLS11PlusSpec() {
359-
return isDTLS ? true : (this.id >= TLS11.id);
359+
return isDTLS || (this.id >= TLS11.id);
360360
}
361361

362362
/**
363363
* Return true if this ProtocolVersion object is of TLS 1.0 or
364364
* newer version.
365365
*/
366366
boolean useTLS10PlusSpec() {
367-
return isDTLS ? true : (this.id >= TLS10.id);
367+
return isDTLS || (this.id >= TLS10.id);
368368
}
369369

370370
/**
371371
* Return true if this ProtocolVersion object is of TLS 1.0 or
372372
* newer version.
373373
*/
374374
static boolean useTLS10PlusSpec(int id, boolean isDTLS) {
375-
return isDTLS ? true : (id >= TLS10.id);
375+
return isDTLS || (id >= TLS10.id);
376376
}
377377

378378
/**

src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 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
@@ -837,7 +837,7 @@ private void shutdownInput(
837837
@Override
838838
public boolean isInputShutdown() {
839839
return conContext.isInboundClosed() &&
840-
((autoClose || !isLayered()) ? super.isInputShutdown(): true);
840+
(!autoClose && isLayered() || super.isInputShutdown());
841841
}
842842

843843
// Please don't synchronized this method. Otherwise, the read and close
@@ -861,7 +861,7 @@ public void shutdownOutput() throws IOException {
861861
@Override
862862
public boolean isOutputShutdown() {
863863
return conContext.isOutboundClosed() &&
864-
((autoClose || !isLayered()) ? super.isOutputShutdown(): true);
864+
(!autoClose && isLayered() || super.isOutputShutdown());
865865
}
866866

867867
@Override

src/java.base/share/classes/sun/security/ssl/SignatureScheme.java

Lines changed: 3 additions & 3 deletions
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
@@ -364,8 +364,8 @@ private boolean isPermitted(AlgorithmConstraints constraints) {
364364
constraints.permits(SIGNATURE_PRIMITIVE_SET,
365365
this.algorithm, (signAlgParams != null ?
366366
signAlgParams.parameters : null)) &&
367-
(namedGroup != null ?
368-
namedGroup.isPermitted(constraints) : true);
367+
(namedGroup == null ||
368+
namedGroup.isPermitted(constraints));
369369
}
370370

371371
// Get local supported algorithm collection complying to algorithm

src/java.base/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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
@@ -139,7 +139,7 @@ Set<X500Principal> getIssuerX500Principals() {
139139
continue;
140140
}
141141
Key key = ks.getKey(alias, password);
142-
if (key instanceof PrivateKey == false) {
142+
if (!(key instanceof PrivateKey)) {
143143
continue;
144144
}
145145
Certificate[] certs = ks.getCertificateChain(alias);
@@ -334,7 +334,7 @@ private String[] getAliases(String keyType, Principal[] issuers) {
334334
if (issuers == null) {
335335
issuers = new X500Principal[0];
336336
}
337-
if (issuers instanceof X500Principal[] == false) {
337+
if (!(issuers instanceof X500Principal[])) {
338338
// normally, this will never happen but try to recover if it does
339339
issuers = convertPrincipals(issuers);
340340
}
@@ -375,7 +375,7 @@ private String[] getAliases(String keyType, Principal[] issuers) {
375375
certs[0].getSigAlgName().toUpperCase(Locale.ENGLISH);
376376
String pattern = "WITH" +
377377
sigType.toUpperCase(Locale.ENGLISH);
378-
if (sigAlgName.contains(pattern) == false) {
378+
if (!sigAlgName.contains(pattern)) {
379379
continue;
380380
}
381381
}

src/java.base/share/classes/sun/security/ssl/TrustManagerFactoryImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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
@@ -155,13 +155,13 @@ X509TrustManager getInstance(
155155
@Override
156156
X509TrustManager getInstance(ManagerFactoryParameters spec)
157157
throws InvalidAlgorithmParameterException {
158-
if (spec instanceof CertPathTrustManagerParameters == false) {
158+
if (!(spec instanceof CertPathTrustManagerParameters)) {
159159
throw new InvalidAlgorithmParameterException
160160
("Parameters must be CertPathTrustManagerParameters");
161161
}
162162
CertPathParameters params =
163163
((CertPathTrustManagerParameters)spec).getParameters();
164-
if (params instanceof PKIXBuilderParameters == false) {
164+
if (!(params instanceof PKIXBuilderParameters)) {
165165
throw new InvalidAlgorithmParameterException
166166
("Encapsulated parameters must be PKIXBuilderParameters");
167167
}

src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 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
@@ -271,7 +271,7 @@ private PrivateKeyEntry getEntry(String alias) {
271271
KeyStore ks = builder.getKeyStore();
272272
Entry newEntry = ks.getEntry
273273
(keyStoreAlias, builder.getProtectionParameter(alias));
274-
if (newEntry instanceof PrivateKeyEntry == false) {
274+
if (!(newEntry instanceof PrivateKeyEntry)) {
275275
// unexpected type of entry
276276
return null;
277277
}
@@ -581,7 +581,7 @@ CheckResult check(X509Certificate cert, Date date,
581581
// require either signature bit
582582
// or if server also allow key encipherment bit
583583
if (!supportsDigitalSignature) {
584-
if (this == CLIENT || getBit(ku, 2) == false) {
584+
if (this == CLIENT || !getBit(ku, 2)) {
585585
return CheckResult.EXTENSION_MISMATCH;
586586
}
587587
}
@@ -599,7 +599,7 @@ CheckResult check(X509Certificate cert, Date date,
599599
break;
600600
case "DH":
601601
// require keyagreement bit
602-
if (getBit(ku, 4) == false) {
602+
if (!getBit(ku, 4)) {
603603
return CheckResult.EXTENSION_MISMATCH;
604604
}
605605
break;
@@ -614,7 +614,7 @@ CheckResult check(X509Certificate cert, Date date,
614614
// exchange and not ephemeral ECDH. We leave it in
615615
// for now until there are signs that this check
616616
// causes problems for real world EC certificates.
617-
if ((this == SERVER) && (getBit(ku, 4) == false)) {
617+
if (this == SERVER && !getBit(ku, 4)) {
618618
return CheckResult.EXTENSION_MISMATCH;
619619
}
620620
break;
@@ -748,7 +748,7 @@ private List<EntryStatus> getAliases(int builderIndex,
748748

749749
boolean incompatible = false;
750750
for (Certificate cert : chain) {
751-
if (cert instanceof X509Certificate == false) {
751+
if (!(cert instanceof X509Certificate)) {
752752
// not an X509Certificate, ignore this alias
753753
incompatible = true;
754754
break;
@@ -785,7 +785,7 @@ private List<EntryStatus> getAliases(int builderIndex,
785785
break;
786786
}
787787
}
788-
if (found == false) {
788+
if (!found) {
789789
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
790790
SSLLogger.fine(
791791
"Ignore alias " + alias
@@ -820,7 +820,7 @@ private List<EntryStatus> getAliases(int builderIndex,
820820
if (!preferred && checkResult == CheckResult.OK && keyIndex == 0) {
821821
preferred = true;
822822
}
823-
if (preferred && (findAll == false)) {
823+
if (preferred && !findAll) {
824824
// if we have a good match and do not need all matches,
825825
// return immediately
826826
return Collections.singletonList(status);

0 commit comments

Comments
 (0)