8215281: Use String.isEmpty() when applicable in java.base

Reviewed-by: dfuchs, alanb
This commit is contained in:
Claes Redestad 2018-12-13 15:31:05 +01:00
parent c998ead188
commit a3df1d618e
155 changed files with 340 additions and 382 deletions

View file

@ -451,7 +451,7 @@ public class BytecodeName {
* @return true if the name is non-empty and all of its characters are safe
*/
public static boolean isSafeBytecodeName(String s) {
if (s.length() == 0) return false;
if (s.isEmpty()) return false;
// check occurrences of each DANGEROUS char
for (char xc : DANGEROUS_CHARS_A) {
if (xc == ESCAPE_C) continue; // not really that dangerous
@ -476,7 +476,7 @@ public class BytecodeName {
}
private static String mangle(String s) {
if (s.length() == 0)
if (s.isEmpty())
return NULL_ESCAPE;
// build this lazily, when we first need an escape:

View file

@ -76,7 +76,7 @@ public class TransferProtocolClient extends NetworkClient {
System.out.print(response);
}
if (response.length() == 0) {
if (response.isEmpty()) {
code = -1;
} else {
try {

View file

@ -433,7 +433,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
logger.finest("Server [" + serverAddr + "] --> " + response);
}
if (response.length() == 0) {
if (response.isEmpty()) {
code = -1;
} else {
try {
@ -1049,7 +1049,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
if (!isConnected()) {
throw new sun.net.ftp.FtpProtocolException("Not connected yet", FtpReplyCode.BAD_SEQUENCE);
}
if (user == null || user.length() == 0) {
if (user == null || user.isEmpty()) {
throw new IllegalArgumentException("User name can't be null or empty");
}
tryLogin(user, password);
@ -1088,7 +1088,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
if (!isConnected()) {
throw new sun.net.ftp.FtpProtocolException("Not connected yet", FtpReplyCode.BAD_SEQUENCE);
}
if (user == null || user.length() == 0) {
if (user == null || user.isEmpty()) {
throw new IllegalArgumentException("User name can't be null or empty");
}
tryLogin(user, password);
@ -1152,7 +1152,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
* @exception <code>FtpProtocolException</code>
*/
public sun.net.ftp.FtpClient changeDirectory(String remoteDirectory) throws sun.net.ftp.FtpProtocolException, IOException {
if (remoteDirectory == null || "".equals(remoteDirectory)) {
if (remoteDirectory == null || remoteDirectory.isEmpty()) {
throw new IllegalArgumentException("directory can't be null or empty");
}
@ -1738,7 +1738,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
* @throws IOException if an error occurs during the transmission.
*/
public long getSize(String path) throws sun.net.ftp.FtpProtocolException, IOException {
if (path == null || path.length() == 0) {
if (path == null || path.isEmpty()) {
throw new IllegalArgumentException("path can't be null or empty");
}
issueCommandCheck("SIZE " + path);

View file

@ -238,7 +238,7 @@ public class DefaultProxySelector extends ProxySelector {
if (phost != null && phost.length() != 0)
break;
}
if (phost == null || phost.length() == 0) {
if (phost == null || phost.isEmpty()) {
/**
* No system property defined for that
* protocol. Let's check System Proxy
@ -267,7 +267,7 @@ public class DefaultProxySelector extends ProxySelector {
nprop.hostsSource = null;
nprop.pattern = null;
}
} else if (nphosts.length() != 0) {
} else if (!nphosts.isEmpty()) {
// add the required default patterns
// but only if property no set. If it
// is empty, leave empty.

View file

@ -226,7 +226,7 @@ public class HeaderParser {
for (int i=0; k.hasNext(); i++) {
String key = k.next();
String val = findValue (i);
if (val != null && "".equals (val)) {
if (val != null && val.isEmpty()) {
val = null;
}
sb.append(" {").append(key).append(val == null ? "" : "," + val)

View file

@ -201,9 +201,7 @@ public class MimeEntry implements Cloneable {
}
private boolean isStarred(String typeName) {
return (typeName != null)
&& (typeName.length() > 0)
&& (typeName.endsWith("/*"));
return typeName != null && typeName.endsWith("/*");
}
/**
@ -300,7 +298,7 @@ public class MimeEntry implements Cloneable {
}
String extensions = getExtensionsAsList();
if (extensions.length() > 0) {
if (!extensions.isEmpty()) {
sj.add("file_extensions=" + extensions);
}

View file

@ -162,7 +162,7 @@ class MimeLauncher extends Thread {
location the application. If a valid path is not found, it
returns false else true. */
private boolean findExecutablePath(String str) {
if (str == null || str.length() == 0) {
if (str == null || str.isEmpty()) {
return false;
}

View file

@ -536,8 +536,7 @@ public final class ParseUtil {
throws URISyntaxException
{
if (scheme != null) {
if ((path != null)
&& ((path.length() > 0) && (path.charAt(0) != '/')))
if (path != null && !path.isEmpty() && path.charAt(0) != '/')
throw new URISyntaxException(s,
"Relative path in absolute URI");
}

View file

@ -603,7 +603,7 @@ public class HttpClient extends NetworkClient {
StringBuilder result = new StringBuilder(128);
result.append(url.getProtocol());
result.append(":");
if (url.getAuthority() != null && url.getAuthority().length() > 0) {
if (url.getAuthority() != null && !url.getAuthority().isEmpty()) {
result.append("//");
result.append(url.getAuthority());
}
@ -619,7 +619,7 @@ public class HttpClient extends NetworkClient {
} else {
fileName = url.getFile();
if ((fileName == null) || (fileName.length() == 0)) {
if ((fileName == null) || (fileName.isEmpty())) {
fileName = "/";
} else if (fileName.charAt(0) == '?') {
/* HTTP/1.1 spec says in 5.1.2. about Request-URI:

View file

@ -341,7 +341,7 @@ public class FtpURLConnection extends URLConnection {
path.charAt(0) == '/') {
path = path.substring(1);
}
if (path == null || path.length() == 0) {
if (path == null || path.isEmpty()) {
path = "./";
}
if (!path.endsWith("/")) {
@ -555,7 +555,7 @@ public class FtpURLConnection extends URLConnection {
}
decodePath(url.getPath());
if (filename == null || filename.length() == 0) {
if (filename == null || filename.isEmpty()) {
throw new IOException("illegal filename for a PUT");
}
try {

View file

@ -248,7 +248,7 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
this.realm = realm;
String urlPath = url.getPath();
if (urlPath.length() == 0)
if (urlPath.isEmpty())
this.path = urlPath;
else {
this.path = reducePath (urlPath);

View file

@ -279,7 +279,7 @@ class DigestAuthentication extends AuthenticationInfo {
if (s == null || !s.equals("true"))
return false;
String newNonce = p.findValue ("nonce");
if (newNonce == null || "".equals(newNonce)) {
if (newNonce == null || newNonce.isEmpty()) {
return false;
}
params.setNonce (newNonce);
@ -323,7 +323,7 @@ class DigestAuthentication extends AuthenticationInfo {
+ authMethod.substring(1).toLowerCase();
}
String algorithm = p.findValue("algorithm");
if (algorithm == null || "".equals(algorithm)) {
if (algorithm == null || algorithm.isEmpty()) {
algorithm = "MD5"; // The default, accoriding to rfc2069
}
params.setAlgorithm (algorithm);
@ -451,7 +451,7 @@ class DigestAuthentication extends AuthenticationInfo {
}
/* Check if there is a nextnonce field */
String nextnonce = p.findValue ("nextnonce");
if (nextnonce != null && ! "".equals(nextnonce)) {
if (nextnonce != null && !nextnonce.isEmpty()) {
params.setNonce (nextnonce);
}

View file

@ -3026,7 +3026,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
// Filtering only if there is a cookie handler. [Assumption: the
// cookie handler will store/retrieve the HttpOnly cookies]
if (cookieHandler == null || value.length() == 0)
if (cookieHandler == null || value.isEmpty())
return value;
JavaNetHttpCookieAccess access =

View file

@ -143,7 +143,7 @@ final class HttpsClient extends HttpClient
String cipherString =
GetPropertyAction.privilegedGetProperty("https.cipherSuites");
if (cipherString == null || "".equals(cipherString)) {
if (cipherString == null || cipherString.isEmpty()) {
ciphers = null;
} else {
StringTokenizer tokenizer;
@ -167,7 +167,7 @@ final class HttpsClient extends HttpClient
String protocolString =
GetPropertyAction.privilegedGetProperty("https.protocols");
if (protocolString == null || "".equals(protocolString)) {
if (protocolString == null || protocolString.isEmpty()) {
protocols = null;
} else {
StringTokenizer tokenizer;
@ -187,7 +187,7 @@ final class HttpsClient extends HttpClient
private String getUserAgent() {
String userAgent =
GetPropertyAction.privilegedGetProperty("https.agent");
if (userAgent == null || userAgent.length() == 0) {
if (userAgent == null || userAgent.isEmpty()) {
userAgent = "JSSE";
}
return userAgent;

View file

@ -66,7 +66,7 @@ public class JavaRuntimeURLConnection extends URLConnection {
JavaRuntimeURLConnection(URL url) throws IOException {
super(url);
String path = url.getPath();
if (path.length() == 0 || path.charAt(0) != '/')
if (path.isEmpty() || path.charAt(0) != '/')
throw new MalformedURLException(url + " missing path or /");
if (path.length() == 1) {
this.module = null;

View file

@ -403,14 +403,8 @@ public class Net {
public static boolean isFastTcpLoopbackRequested() {
String loopbackProp = GetPropertyAction
.privilegedGetProperty("jdk.net.useFastTcpLoopback");
boolean enable;
if ("".equals(loopbackProp)) {
enable = true;
} else {
enable = Boolean.parseBoolean(loopbackProp);
}
return enable;
.privilegedGetProperty("jdk.net.useFastTcpLoopback", "false");
return loopbackProp.isEmpty() ? true : Boolean.parseBoolean(loopbackProp);
}
// -- Socket operations --

View file

@ -73,7 +73,7 @@ public abstract class AbstractFileSystemProvider extends FileSystemProvider {
throws IOException
{
String[] s = split(attribute);
if (s[0].length() == 0)
if (s[0].isEmpty())
throw new IllegalArgumentException(attribute);
DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
if (view == null)
@ -86,7 +86,7 @@ public abstract class AbstractFileSystemProvider extends FileSystemProvider {
throws IOException
{
String[] s = split(attributes);
if (s[0].length() == 0)
if (s[0].isEmpty())
throw new IllegalArgumentException(attributes);
DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
if (view == null)

View file

@ -83,7 +83,7 @@ abstract class AbstractUserDefinedFileAttributeView
names = list();
break;
} else {
if (name.length() == 0)
if (name.isEmpty())
throw new IllegalArgumentException();
names.add(name);
}

View file

@ -75,7 +75,7 @@ public class GetInstance {
public static Service getService(String type, String algorithm,
String provider) throws NoSuchAlgorithmException,
NoSuchProviderException {
if ((provider == null) || (provider.length() == 0)) {
if (provider == null || provider.isEmpty()) {
throw new IllegalArgumentException("missing provider");
}
Provider p = Providers.getProviderList().getProvider(provider);

View file

@ -114,7 +114,7 @@ final class ProviderConfig {
}
private boolean hasArgument() {
return argument.length() != 0;
return !argument.isEmpty();
}
// should we try to load this provider?

View file

@ -175,7 +175,7 @@ public final class ProviderList {
while ((entry = Security.getProperty("security.provider." + i)) != null) {
entry = entry.trim();
if (entry.length() == 0) {
if (entry.isEmpty()) {
System.err.println("invalid entry for " +
"security.provider." + i);
break;
@ -200,7 +200,7 @@ public final class ProviderList {
// Load config entries for use when getInstance is called
entry = Security.getProperty("jdk.security.provider.preferred");
if (entry != null && (entry = entry.trim()).length() > 0) {
if (entry != null && !(entry = entry.trim()).isEmpty()) {
String[] entries = entry.split(",");
if (ProviderList.preferredPropList == null) {
ProviderList.preferredPropList = new PreferredList();

View file

@ -626,7 +626,7 @@ public final class ConfigFile extends Configuration {
return url.openStream();
} catch (Exception e) {
String file = url.getPath();
if (url.getHost().length() > 0) { // For Windows UNC
if (!url.getHost().isEmpty()) { // For Windows UNC
file = "//" + url.getHost() + file;
}
if (debugConfig != null) {
@ -651,7 +651,7 @@ public final class ConfigFile extends Configuration {
return value;
}
String s = PropertyExpander.expand(value);
if (s == null || s.length() == 0) {
if (s == null || s.isEmpty()) {
throw ioException(
"Configuration.Error.Line.line.system.property.value.expanded.to.empty.value",
linenum, value);

View file

@ -391,9 +391,9 @@ public class PolicyParser {
out.print("keystore \"");
out.print(keyStoreUrlString);
out.print('"');
if (keyStoreType != null && keyStoreType.length() > 0)
if (keyStoreType != null && !keyStoreType.isEmpty())
out.print(", \"" + keyStoreType + "\"");
if (keyStoreProvider != null && keyStoreProvider.length() > 0)
if (keyStoreProvider != null && !keyStoreProvider.isEmpty())
out.print(", \"" + keyStoreProvider + "\"");
out.println(";");
out.println();
@ -446,7 +446,7 @@ public class PolicyParser {
String alias = aliases.nextToken().trim();
if (alias.equals(","))
cctr++;
else if (alias.length() > 0)
else if (!alias.isEmpty())
actr++;
}
if (actr <= cctr)

View file

@ -113,7 +113,7 @@ abstract class SeedGenerator {
+ "generator: " + e.toString());
}
}
} else if (egdSource.length() != 0) {
} else if (!egdSource.isEmpty()) {
try {
instance = new URLSeedGenerator(egdSource);
if (debug != null) {

View file

@ -440,7 +440,7 @@ final class CertificateMessage {
// It is not necessary to check the certificate update if
// endpoint identification is enabled.
String identityAlg = chc.sslConfig.identificationProtocol;
if ((identityAlg == null || identityAlg.length() == 0) &&
if ((identityAlg == null || identityAlg.isEmpty()) &&
!isIdentityEquivalent(x509Certs[0],
chc.reservedServerCerts[0])) {
chc.conContext.fatal(Alert.BAD_CERTIFICATE,

View file

@ -491,7 +491,7 @@ final class ClientHello {
// It is fine to move on with abbreviate handshake if
// endpoint identification is enabled.
String identityAlg = chc.sslConfig.identificationProtocol;
if ((identityAlg == null || identityAlg.length() == 0)) {
if (identityAlg == null || identityAlg.isEmpty()) {
if (isEmsAvailable) {
if (!session.useExtendedMasterSecret) {
// perform full handshake instead

View file

@ -253,7 +253,7 @@ final class DHKeyExchange {
static {
String property = GetPropertyAction.privilegedGetProperty(
"jdk.tls.ephemeralDHKeySize");
if (property == null || property.length() == 0) {
if (property == null || property.isEmpty()) {
useLegacyEphemeralDHKeys = false;
useSmartEphemeralDHKeys = false;
customizedDHKeySize = -1;

View file

@ -237,7 +237,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
public boolean permits(Set<CryptoPrimitive> primitives,
String algorithm, AlgorithmParameters parameters) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
throw new IllegalArgumentException(
"No algorithm name specified");
}
@ -276,7 +276,7 @@ final class SSLAlgorithmConstraints implements AlgorithmConstraints {
public final boolean permits(Set<CryptoPrimitive> primitives,
String algorithm, Key key, AlgorithmParameters parameters) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
throw new IllegalArgumentException(
"No algorithm name specified");
}

View file

@ -436,7 +436,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
"System property " + propertyName + " is set to '" +
property + "'");
}
if (property != null && property.length() != 0) {
if (property != null && !property.isEmpty()) {
// remove double quote marks from beginning/end of the property
if (property.length() > 1 && property.charAt(0) == '"' &&
property.charAt(property.length() - 1) == '"') {
@ -444,7 +444,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
}
}
if (property != null && property.length() != 0) {
if (property != null && !property.isEmpty()) {
String[] cipherSuiteNames = property.split(",");
Collection<CipherSuite> cipherSuites =
new ArrayList<>(cipherSuiteNames.length);
@ -845,7 +845,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
return;
}
if (property.length() != 0) {
if (!property.isEmpty()) {
// remove double quote marks from beginning/end of the property
if (property.length() > 1 && property.charAt(0) == '"' &&
property.charAt(property.length() - 1) == '"') {
@ -853,7 +853,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
}
}
if (property.length() != 0) {
if (!property.isEmpty()) {
String[] protocols = property.split(",");
for (int i = 0; i < protocols.length; i++) {
protocols[i] = protocols[i].trim();
@ -1109,7 +1109,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
KeyStore ks = null;
char[] passwd = null;
try {
if (defaultKeyStore.length() != 0 &&
if (!defaultKeyStore.isEmpty() &&
!NONE.equals(defaultKeyStore)) {
fs = AccessController.doPrivileged(
new PrivilegedExceptionAction<FileInputStream>() {
@ -1121,7 +1121,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
}
String defaultKeyStorePassword = props.get("keyStorePasswd");
if (defaultKeyStorePassword.length() != 0) {
if (!defaultKeyStorePassword.isEmpty()) {
passwd = defaultKeyStorePassword.toCharArray();
}
@ -1132,7 +1132,7 @@ public abstract class SSLContextImpl extends SSLContextSpi {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,defaultctx")) {
SSLLogger.finest("init keystore");
}
if (defaultKeyStoreProvider.length() == 0) {
if (defaultKeyStoreProvider.isEmpty()) {
ks = KeyStore.getInstance(defaultKeyStoreType);
} else {
ks = KeyStore.getInstance(defaultKeyStoreType,
@ -1561,7 +1561,7 @@ final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
// check endpoint identity
String identityAlg = sslSocket.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
if (identityAlg != null && !identityAlg.isEmpty()) {
String hostname = session.getPeerHost();
X509TrustManagerImpl.checkIdentity(
hostname, chain[0], identityAlg);
@ -1601,7 +1601,7 @@ final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
// check endpoint identity
String identityAlg = engine.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
if (identityAlg != null && !identityAlg.isEmpty()) {
String hostname = session.getPeerHost();
X509TrustManagerImpl.checkIdentity(
hostname, chain[0], identityAlg);

View file

@ -1203,7 +1203,7 @@ public final class SSLSocketImpl
synchronized void doneConnect() throws IOException {
// In server mode, it is not necessary to set host and serverNames.
// Otherwise, would require a reverse DNS lookup to get the hostname.
if ((peerHost == null) || (peerHost.length() == 0)) {
if (peerHost == null || peerHost.isEmpty()) {
boolean useNameService =
trustNameService && conContext.sslConfig.isClientMode;
useImplicitHost(useNameService);
@ -1238,8 +1238,7 @@ public final class SSLSocketImpl
JavaNetInetAddressAccess jna =
SharedSecrets.getJavaNetInetAddressAccess();
String originalHostname = jna.getOriginalHostName(inetAddress);
if ((originalHostname != null) &&
(originalHostname.length() != 0)) {
if (originalHostname != null && !originalHostname.isEmpty()) {
this.peerHost = originalHostname;
if (conContext.sslConfig.serverNames.isEmpty() &&

View file

@ -483,7 +483,7 @@ final class SupportedGroupsExtension {
// default groups and preferences will be used.
String property = GetPropertyAction
.privilegedGetProperty("jdk.tls.namedGroups");
if (property != null && property.length() != 0) {
if (property != null && !property.isEmpty()) {
// remove double quote marks from beginning/end of the property
if (property.length() > 1 && property.charAt(0) == '"' &&
property.charAt(property.length() - 1) == '"') {
@ -492,7 +492,7 @@ final class SupportedGroupsExtension {
}
ArrayList<NamedGroup> groupList;
if (property != null && property.length() != 0) {
if (property != null && !property.isEmpty()) {
String[] groups = property.split(",");
groupList = new ArrayList<>(groups.length);
for (String group : groups) {

View file

@ -148,7 +148,7 @@ final class X509TrustManagerImpl extends X509ExtendedTrustManager
"null or zero-length certificate chain");
}
if (authType == null || authType.length() == 0) {
if (authType == null || authType.isEmpty()) {
throw new IllegalArgumentException(
"null or zero-length authentication type");
}
@ -229,7 +229,7 @@ final class X509TrustManagerImpl extends X509ExtendedTrustManager
// check endpoint identity
String identityAlg = sslSocket.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
if (identityAlg != null && !identityAlg.isEmpty()) {
checkIdentity(session, trustedChain[0], identityAlg, isClient,
getRequestedServerNames(socket), chainsToPublicCA);
}
@ -287,7 +287,7 @@ final class X509TrustManagerImpl extends X509ExtendedTrustManager
// check endpoint identity
String identityAlg = engine.getSSLParameters().
getEndpointIdentificationAlgorithm();
if (identityAlg != null && identityAlg.length() != 0) {
if (identityAlg != null && !identityAlg.isEmpty()) {
checkIdentity(session, trustedChain[0], identityAlg, isClient,
getRequestedServerNames(engine), chainsToPublicCA);
}
@ -448,7 +448,7 @@ final class X509TrustManagerImpl extends X509ExtendedTrustManager
private static void checkIdentity(String hostname, X509Certificate cert,
String algorithm, boolean chainsToPublicCA)
throws CertificateException {
if (algorithm != null && algorithm.length() != 0) {
if (algorithm != null && !algorithm.isEmpty()) {
// if IPv6 strip off the "[]"
if ((hostname != null) && hostname.startsWith("[") &&
hostname.endsWith("]")) {

View file

@ -46,9 +46,9 @@ public class PathList {
* @return the resulting path
*/
public static String appendPath(String pathTo, String pathFrom) {
if (pathTo == null || pathTo.length() == 0) {
if (pathTo == null || pathTo.isEmpty()) {
return pathFrom;
} else if (pathFrom == null || pathFrom.length() == 0) {
} else if (pathFrom == null || pathFrom.isEmpty()) {
return pathTo;
} else {
return pathTo + File.pathSeparator + pathFrom;

View file

@ -75,7 +75,7 @@ public abstract class AbstractAlgorithmConstraints
static boolean checkAlgorithm(String[] algorithms, String algorithm,
AlgorithmDecomposer decomposer) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
throw new IllegalArgumentException("No algorithm name specified");
}

View file

@ -80,7 +80,7 @@ public class AlgorithmDecomposer {
* Please override the method if need to support more name pattern.
*/
public Set<String> decompose(String algorithm) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
return new HashSet<>();
}
@ -167,7 +167,7 @@ public class AlgorithmDecomposer {
* message digest algorithm name to avoid overly complicated checking.
*/
public static Set<String> decomposeOneHash(String algorithm) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
return new HashSet<>();
}

View file

@ -135,7 +135,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
public final boolean permits(Set<CryptoPrimitive> primitives,
String algorithm, Key key, AlgorithmParameters parameters) {
if (algorithm == null || algorithm.length() == 0) {
if (algorithm == null || algorithm.isEmpty()) {
throw new IllegalArgumentException("No algorithm name specified");
}
@ -188,7 +188,7 @@ public class DisabledAlgorithmConstraints extends AbstractAlgorithmConstraints {
}
// check the signature algorithm with parameters
if (algorithm != null && algorithm.length() != 0) {
if (algorithm != null && !algorithm.isEmpty()) {
if (!permits(primitives, algorithm, parameters)) {
return false;
}

View file

@ -423,7 +423,7 @@ public class SignatureFileVerifier {
// This means we have an error in finding weak algorithms, run in
// debug mode to see permittedAlgs map's values.
if (w.length() == 0) {
if (w.isEmpty()) {
return "Unknown Algorithm(s)";
}

View file

@ -1245,7 +1245,7 @@ class AVAKeyword {
}
boolean number = false;
if (keyword.length() != 0) {
if (!keyword.isEmpty()) {
char ch = keyword.charAt(0);
if ((ch >= '0') && (ch <= '9')) {
number = true;
@ -1285,7 +1285,7 @@ class AVAKeyword {
return ak.keyword;
}
} else {
if (keywordString.length() == 0) {
if (keywordString.isEmpty()) {
throw new IllegalArgumentException("keyword cannot be empty");
}
keywordString = keywordString.trim();

View file

@ -72,7 +72,7 @@ public class DNSName implements GeneralNameInterface {
* @throws IOException if the name is not a valid DNSName subjectAltName
*/
public DNSName(String name) throws IOException {
if (name == null || name.length() == 0)
if (name == null || name.isEmpty())
throw new IOException("DNSName must not be null or empty");
if (name.contains(" "))
throw new IOException("DNSName with blank components is not permitted");

View file

@ -125,7 +125,7 @@ public class IPAddressName implements GeneralNameInterface {
*/
public IPAddressName(String name) throws IOException {
if (name == null || name.length() == 0) {
if (name == null || name.isEmpty()) {
throw new IOException("IPAddress cannot be null or empty");
}
if (name.charAt(name.length() - 1) == '/') {

View file

@ -121,7 +121,7 @@ public class RDN {
* Plus sign is a separator
*/
String avaString = name.substring(avaOffset, nextPlus);
if (avaString.length() == 0) {
if (avaString.isEmpty()) {
throw new IOException("empty AVA in RDN \"" + name + "\"");
}
@ -141,7 +141,7 @@ public class RDN {
// parse last or only AVA
String avaString = name.substring(avaOffset);
if (avaString.length() == 0) {
if (avaString.isEmpty()) {
throw new IOException("empty AVA in RDN \"" + name + "\"");
}
AVA ava = new AVA(new StringReader(avaString), keywordMap);
@ -199,7 +199,7 @@ public class RDN {
* Plus sign is a separator
*/
String avaString = name.substring(avaOffset, nextPlus);
if (avaString.length() == 0) {
if (avaString.isEmpty()) {
throw new IOException("empty AVA in RDN \"" + name + "\"");
}
@ -217,7 +217,7 @@ public class RDN {
// parse last or only AVA
String avaString = name.substring(avaOffset);
if (avaString.length() == 0) {
if (avaString.isEmpty()) {
throw new IOException("empty AVA in RDN \"" + name + "\"");
}
AVA ava = new AVA(new StringReader(avaString), AVA.RFC2253, keywordMap);

View file

@ -79,12 +79,12 @@ public class RFC822Name implements GeneralNameInterface
* @throws IOException if name is not valid
*/
public void parseName(String name) throws IOException {
if (name == null || name.length() == 0) {
if (name == null || name.isEmpty()) {
throw new IOException("RFC822Name may not be null or empty");
}
// See if domain is a valid domain name
String domain = name.substring(name.indexOf('@')+1);
if (domain.length() == 0) {
if (domain.isEmpty()) {
throw new IOException("RFC822Name may not end with @");
} else {
//An RFC822 NameConstraint could start with a ., although

View file

@ -865,7 +865,7 @@ public class X500Name implements GeneralNameInterface, Principal {
*/
private void parseDN(String input, Map<String, String> keywordMap)
throws IOException {
if (input == null || input.length() == 0) {
if (input == null || input.isEmpty()) {
names = new RDN[0];
return;
}
@ -937,7 +937,7 @@ public class X500Name implements GeneralNameInterface, Principal {
}
private void parseRFC2253DN(String dnString) throws IOException {
if (dnString.length() == 0) {
if (dnString.isEmpty()) {
names = new RDN[0];
return;
}

View file

@ -370,7 +370,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
throw new CRLException("Uninitialized CRL");
}
Signature sigVerf = null;
if (sigProvider.length() == 0) {
if (sigProvider.isEmpty()) {
sigVerf = Signature.getInstance(sigAlgId.getName());
} else {
sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
@ -495,7 +495,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
if (readOnly)
throw new CRLException("cannot over-write existing CRL");
Signature sigEngine = null;
if ((provider == null) || (provider.length() == 0))
if (provider == null || provider.isEmpty())
sigEngine = Signature.getInstance(algorithm);
else
sigEngine = Signature.getInstance(algorithm, provider);

View file

@ -429,7 +429,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
}
// Verify the signature ...
Signature sigVerf = null;
if (sigProvider.length() == 0) {
if (sigProvider.isEmpty()) {
sigVerf = Signature.getInstance(algId.getName());
} else {
sigVerf = Signature.getInstance(algId.getName(), sigProvider);
@ -598,7 +598,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
throw new CertificateEncodingException(
"cannot over-write existing certificate");
Signature sigEngine = null;
if ((provider == null) || (provider.length() == 0))
if (provider == null || provider.isEmpty())
sigEngine = Signature.getInstance(algorithm);
else
sigEngine = Signature.getInstance(algorithm, provider);

View file

@ -331,7 +331,7 @@ public final class InternalLocaleBuilder {
done.add(key);
}
}
if (privateuse != null && privateuse.length() > 0) {
if (privateuse != null && !privateuse.isEmpty()) {
// privateuse string contains prefix, e.g. "x-abc-def"
if (extensions == null) {
extensions = new HashMap<>(1);
@ -406,19 +406,19 @@ public final class InternalLocaleBuilder {
// Validate base locale fields before updating internal state.
// LocaleExtensions always store validated/canonicalized values,
// so no checks are necessary.
if (language.length() > 0 && !LanguageTag.isLanguage(language)) {
if (!language.isEmpty() && !LanguageTag.isLanguage(language)) {
throw new LocaleSyntaxException("Ill-formed language: " + language);
}
if (script.length() > 0 && !LanguageTag.isScript(script)) {
if (!script.isEmpty() && !LanguageTag.isScript(script)) {
throw new LocaleSyntaxException("Ill-formed script: " + script);
}
if (region.length() > 0 && !LanguageTag.isRegion(region)) {
if (!region.isEmpty() && !LanguageTag.isRegion(region)) {
throw new LocaleSyntaxException("Ill-formed region: " + region);
}
if (variant.length() > 0) {
if (!variant.isEmpty()) {
int errIdx = checkVariants(variant, BaseLocale.SEP);
if (errIdx != -1) {
throw new LocaleSyntaxException("Ill-formed variant: " + variant, errIdx);

View file

@ -212,7 +212,7 @@ public class LanguageTag {
if (!itr.isDone() && !sts.isError()) {
String s = itr.current();
sts.errorIndex = itr.currentStart();
if (s.length() == 0) {
if (s.isEmpty()) {
sts.errorMsg = "Empty subtag";
} else {
sts.errorMsg = "Invalid subtag: " + s;
@ -454,7 +454,7 @@ public class LanguageTag {
variant = "";
}
if (variant.length() > 0) {
if (!variant.isEmpty()) {
List<String> variants = null;
StringTokenIterator varitr = new StringTokenIterator(variant, BaseLocale.SEP);
while (!varitr.isDone()) {
@ -527,7 +527,7 @@ public class LanguageTag {
tag.privateuse = privateuse;
}
if (tag.language.length() == 0 && (hasSubtag || privateuse == null)) {
if (tag.language.isEmpty() && (hasSubtag || privateuse == null)) {
// use lang "und" when 1) no language is available AND
// 2) any of other subtags other than private use are available or
// no private use tag is available
@ -712,18 +712,18 @@ public class LanguageTag {
public String toString() {
StringBuilder sb = new StringBuilder();
if (language.length() > 0) {
if (!language.isEmpty()) {
sb.append(language);
for (String extlang : extlangs) {
sb.append(SEP).append(extlang);
}
if (script.length() > 0) {
if (!script.isEmpty()) {
sb.append(SEP).append(script);
}
if (region.length() > 0) {
if (!region.isEmpty()) {
sb.append(SEP).append(region);
}
@ -735,7 +735,7 @@ public class LanguageTag {
sb.append(SEP).append(extension);
}
}
if (privateuse.length() > 0) {
if (!privateuse.isEmpty()) {
if (sb.length() > 0) {
sb.append(SEP);
}

View file

@ -402,7 +402,7 @@ public final class LocaleMatcher {
}
String rangeForRegex = range.replace("*", "\\p{Alnum}*");
while (rangeForRegex.length() > 0) {
while (!rangeForRegex.isEmpty()) {
for (String tag : tags) {
// change to lowercase for case-insensitive matching
String lowerCaseTag = tag.toLowerCase(Locale.ROOT);
@ -437,7 +437,7 @@ public final class LocaleMatcher {
}
String rangeForRegex = range.replace("*", "\\p{Alnum}*");
while (rangeForRegex.length() > 0) {
while (!rangeForRegex.isEmpty()) {
if (tag.matches(rangeForRegex)) {
return true;
}
@ -591,7 +591,7 @@ public final class LocaleMatcher {
private static String[] getEquivalentsForLanguage(String range) {
String r = range;
while (r.length() > 0) {
while (!r.isEmpty()) {
if (LocaleEquivalentMaps.singleEquivMap.containsKey(r)) {
String equiv = LocaleEquivalentMaps.singleEquivMap.get(r);
// Return immediately for performance if the first matching
@ -680,7 +680,7 @@ public final class LocaleMatcher {
String r = range;
boolean hasEquivalent = false;
while (r.length() > 0) {
while (!r.isEmpty()) {
if (keyMap.containsKey(r)) {
hasEquivalent = true;
List<String> equivalents = map.get(keyMap.get(r));

View file

@ -207,7 +207,7 @@ public final class LocaleUtils {
}
static boolean isEmpty(String str) {
return str == null || str.length() == 0;
return str == null || str.isEmpty();
}
static boolean isEmpty(Set<?> set) {

View file

@ -80,7 +80,7 @@ public class UnicodeLocaleExtension extends Extension {
String value = keyword.getValue();
sj.add(key);
if (value.length() > 0) {
if (!value.isEmpty()) {
sj.add(value);
}
}

View file

@ -117,7 +117,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
}
name = strings[value];
// If name is empty in standalone, try its `format' style.
if (name.length() == 0
if (name.isEmpty()
&& (style == SHORT_STANDALONE || style == LONG_STANDALONE
|| style == NARROW_STANDALONE)) {
name = getDisplayName(calendarType, field, value,
@ -183,7 +183,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
String name = strings[i];
// Ignore any empty string (some standalone month names
// are not defined)
if (name.length() == 0) {
if (name.isEmpty()) {
continue;
}
map.put(name, base + i);

View file

@ -503,7 +503,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
*/
String supportedLocaleString = createSupportedLocaleString("AvailableLocales");
if (supportedLocaleString.length() == 0) {
if (supportedLocaleString.isEmpty()) {
throw new InternalError("No available locales for JRE");
}

View file

@ -121,7 +121,7 @@ public abstract class LocaleProviderAdapter {
List<Type> typeList = new ArrayList<>();
// Check user specified adapter preference
if (order != null && order.length() != 0) {
if (order != null && !order.isEmpty()) {
String[] types = order.split(",");
for (String type : types) {
type = type.trim().toUpperCase(Locale.ROOT);