Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8259223: Simplify boolean expression in the SunJSSE provider
Reviewed-by: mullan
  • Loading branch information
XueleiFan committed Jan 5, 2021
1 parent 1b60acd commit 4d3d599
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/sun/security/ssl/CipherSuite.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -890,7 +890,7 @@ private CipherSuite(int id, boolean isDefaultEnabled,
this.macAlg = macAlg;
this.hashAlg = hashAlg;

this.exportable = (cipher == null ? false : cipher.exportable);
this.exportable = (cipher != null && cipher.exportable);
}

static CipherSuite nameOf(String ciperSuiteName) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -128,7 +128,7 @@ private boolean isValid() {
* Return the KeyPair or null if it is invalid.
*/
private KeyPair getKeyPair() {
if (isValid() == false) {
if (!isValid()) {
keyPair = null;
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/sun/security/ssl/Finished.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -325,7 +325,7 @@ public byte[] createVerifyData(HandshakeContext context,
}
}

// TLS 1.2
// TLS 1.3
private static final
class T13VerifyDataGenerator implements VerifyDataGenerator {
private static final byte[] hkdfLabel = "tls13 finished".getBytes();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -576,7 +576,7 @@ private static boolean isActivatable(CipherSuite suite,

retval |= groupAvailable;
} else {
retval |= true;
retval = true;
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -99,7 +99,7 @@ protected void engineInit(KeyStore ks, char[] password) throws
@Override
protected void engineInit(ManagerFactoryParameters params) throws
InvalidAlgorithmParameterException {
if (params instanceof KeyStoreBuilderParameters == false) {
if (!(params instanceof KeyStoreBuilderParameters)) {
throw new InvalidAlgorithmParameterException(
"Parameters must be instance of KeyStoreBuilderParameters");
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -356,23 +356,23 @@ boolean useTLS12PlusSpec() {
* TLS 1.1/DTLS 1.0 or newer version.
*/
boolean useTLS11PlusSpec() {
return isDTLS ? true : (this.id >= TLS11.id);
return isDTLS || (this.id >= TLS11.id);
}

/**
* Return true if this ProtocolVersion object is of TLS 1.0 or
* newer version.
*/
boolean useTLS10PlusSpec() {
return isDTLS ? true : (this.id >= TLS10.id);
return isDTLS || (this.id >= TLS10.id);
}

/**
* Return true if this ProtocolVersion object is of TLS 1.0 or
* newer version.
*/
static boolean useTLS10PlusSpec(int id, boolean isDTLS) {
return isDTLS ? true : (id >= TLS10.id);
return isDTLS || (id >= TLS10.id);
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -837,7 +837,7 @@ private void shutdownInput(
@Override
public boolean isInputShutdown() {
return conContext.isInboundClosed() &&
((autoClose || !isLayered()) ? super.isInputShutdown(): true);
(!autoClose && isLayered() || super.isInputShutdown());
}

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

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -364,8 +364,8 @@ private boolean isPermitted(AlgorithmConstraints constraints) {
constraints.permits(SIGNATURE_PRIMITIVE_SET,
this.algorithm, (signAlgParams != null ?
signAlgParams.parameters : null)) &&
(namedGroup != null ?
namedGroup.isPermitted(constraints) : true);
(namedGroup == null ||
namedGroup.isPermitted(constraints));
}

// Get local supported algorithm collection complying to algorithm
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -139,7 +139,7 @@ Set<X500Principal> getIssuerX500Principals() {
continue;
}
Key key = ks.getKey(alias, password);
if (key instanceof PrivateKey == false) {
if (!(key instanceof PrivateKey)) {
continue;
}
Certificate[] certs = ks.getCertificateChain(alias);
Expand Down Expand Up @@ -334,7 +334,7 @@ private String[] getAliases(String keyType, Principal[] issuers) {
if (issuers == null) {
issuers = new X500Principal[0];
}
if (issuers instanceof X500Principal[] == false) {
if (!(issuers instanceof X500Principal[])) {
// normally, this will never happen but try to recover if it does
issuers = convertPrincipals(issuers);
}
Expand Down Expand Up @@ -375,7 +375,7 @@ private String[] getAliases(String keyType, Principal[] issuers) {
certs[0].getSigAlgName().toUpperCase(Locale.ENGLISH);
String pattern = "WITH" +
sigType.toUpperCase(Locale.ENGLISH);
if (sigAlgName.contains(pattern) == false) {
if (!sigAlgName.contains(pattern)) {
continue;
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -155,13 +155,13 @@ X509TrustManager getInstance(
@Override
X509TrustManager getInstance(ManagerFactoryParameters spec)
throws InvalidAlgorithmParameterException {
if (spec instanceof CertPathTrustManagerParameters == false) {
if (!(spec instanceof CertPathTrustManagerParameters)) {
throw new InvalidAlgorithmParameterException
("Parameters must be CertPathTrustManagerParameters");
}
CertPathParameters params =
((CertPathTrustManagerParameters)spec).getParameters();
if (params instanceof PKIXBuilderParameters == false) {
if (!(params instanceof PKIXBuilderParameters)) {
throw new InvalidAlgorithmParameterException
("Encapsulated parameters must be PKIXBuilderParameters");
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -271,7 +271,7 @@ private PrivateKeyEntry getEntry(String alias) {
KeyStore ks = builder.getKeyStore();
Entry newEntry = ks.getEntry
(keyStoreAlias, builder.getProtectionParameter(alias));
if (newEntry instanceof PrivateKeyEntry == false) {
if (!(newEntry instanceof PrivateKeyEntry)) {
// unexpected type of entry
return null;
}
Expand Down Expand Up @@ -581,7 +581,7 @@ CheckResult check(X509Certificate cert, Date date,
// require either signature bit
// or if server also allow key encipherment bit
if (!supportsDigitalSignature) {
if (this == CLIENT || getBit(ku, 2) == false) {
if (this == CLIENT || !getBit(ku, 2)) {
return CheckResult.EXTENSION_MISMATCH;
}
}
Expand All @@ -599,7 +599,7 @@ CheckResult check(X509Certificate cert, Date date,
break;
case "DH":
// require keyagreement bit
if (getBit(ku, 4) == false) {
if (!getBit(ku, 4)) {
return CheckResult.EXTENSION_MISMATCH;
}
break;
Expand All @@ -614,7 +614,7 @@ CheckResult check(X509Certificate cert, Date date,
// exchange and not ephemeral ECDH. We leave it in
// for now until there are signs that this check
// causes problems for real world EC certificates.
if ((this == SERVER) && (getBit(ku, 4) == false)) {
if (this == SERVER && !getBit(ku, 4)) {
return CheckResult.EXTENSION_MISMATCH;
}
break;
Expand Down Expand Up @@ -748,7 +748,7 @@ private List<EntryStatus> getAliases(int builderIndex,

boolean incompatible = false;
for (Certificate cert : chain) {
if (cert instanceof X509Certificate == false) {
if (!(cert instanceof X509Certificate)) {
// not an X509Certificate, ignore this alias
incompatible = true;
break;
Expand Down Expand Up @@ -785,7 +785,7 @@ private List<EntryStatus> getAliases(int builderIndex,
break;
}
}
if (found == false) {
if (!found) {
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
SSLLogger.fine(
"Ignore alias " + alias
Expand Down Expand Up @@ -820,7 +820,7 @@ private List<EntryStatus> getAliases(int builderIndex,
if (!preferred && checkResult == CheckResult.OK && keyIndex == 0) {
preferred = true;
}
if (preferred && (findAll == false)) {
if (preferred && !findAll) {
// if we have a good match and do not need all matches,
// return immediately
return Collections.singletonList(status);
Expand Down

1 comment on commit 4d3d599

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.