8214971: Replace use of string.equals("") with isEmpty()

Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
This commit is contained in:
Roger Riggs 2018-12-07 11:51:17 -05:00
parent df5b42f33b
commit 938b844088
95 changed files with 195 additions and 195 deletions

View file

@ -1366,7 +1366,7 @@ class ConstantPool {
}
if (tag == CONSTANT_Utf8) {
// Special case: First Utf8 must always be empty string.
assert(cpMap.length == 0 || cpMap[0].stringValue().equals(""));
assert(cpMap.length == 0 || cpMap[0].stringValue().isEmpty());
}
indexByTag[tag] = ix;
// decache indexes derived from this one:

View file

@ -208,7 +208,7 @@ class Driver {
}
}
if (logFile != null && !logFile.equals("")) {
if (logFile != null && !logFile.isEmpty()) {
if (logFile.equals("-")) {
System.setErr(System.out);
} else {
@ -246,7 +246,7 @@ class Driver {
}
newfile = packfile;
// The optional second argument is the source JAR file.
if (jarfile.equals("")) {
if (jarfile.isEmpty()) {
// If only one file is given, it is the only JAR.
// It serves as both input and output.
jarfile = newfile;
@ -352,7 +352,7 @@ class Driver {
if (Utils.isGZIPMagic(Utils.readMagic(inBuf))) {
in = new GZIPInputStream(in);
}
String outfile = newfile.equals("")? jarfile: newfile;
String outfile = newfile.isEmpty()? jarfile: newfile;
OutputStream fileOut;
if (outfile.equals("-"))
fileOut = System.out;
@ -366,7 +366,7 @@ class Driver {
// At this point, we have a good jarfile (or newfile, if -r)
}
if (!bakfile.equals("")) {
if (!bakfile.isEmpty()) {
// On success, abort jarfile recovery bracket.
new File(bakfile).delete();
bakfile = "";
@ -374,13 +374,13 @@ class Driver {
} finally {
// Close jarfile recovery bracket.
if (!bakfile.equals("")) {
if (!bakfile.isEmpty()) {
File jarFile = new File(jarfile);
jarFile.delete(); // Win32 requires this, see above
new File(bakfile).renameTo(jarFile);
}
// In all cases, delete temporary *.pack.
if (!tmpfile.equals(""))
if (!tmpfile.isEmpty())
new File(tmpfile).delete();
}
}

View file

@ -685,7 +685,7 @@ class Package {
return; // do not choose yet
}
String canonName = canonicalFileName();
if (file.nameString.equals("")) {
if (file.nameString.isEmpty()) {
file.nameString = canonName;
}
if (file.nameString.equals(canonName)) {
@ -706,7 +706,7 @@ class Package {
public java.io.File getFileName(java.io.File parent) {
String name = file.name.stringValue();
if (name.equals(""))
if (name.isEmpty())
name = canonicalFileName();
String fname = name.replace('/', java.io.File.separatorChar);
return new java.io.File(parent, fname);
@ -779,7 +779,7 @@ class Package {
}
public boolean isTrivialClassStub() {
return isClassStub()
&& name.stringValue().equals("")
&& name.stringValue().isEmpty()
&& (modtime == NO_MODTIME || modtime == default_modtime)
&& (options &~ FO_IS_CLASS_STUB) == 0;
}

View file

@ -646,7 +646,7 @@ class PackageWriter extends BandStructure {
return; // nothing to write
// The first element must always be the empty string.
assert(cpMap[0].stringValue().equals(""));
assert(cpMap[0].stringValue().isEmpty());
final int SUFFIX_SKIP_1 = 1;
final int PREFIX_SKIP_2 = 2;

View file

@ -237,7 +237,7 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
final long segmentLimit;
{
long limit;
if (props.getProperty(Pack200.Packer.SEGMENT_LIMIT, "").equals(""))
if (props.getProperty(Pack200.Packer.SEGMENT_LIMIT, "").isEmpty())
limit = -1;
else
limit = props.getLong(Pack200.Packer.SEGMENT_LIMIT);

View file

@ -257,7 +257,7 @@ public class File
*/
private File(String child, File parent) {
assert parent.path != null;
assert (!parent.path.equals(""));
assert (!parent.path.isEmpty());
this.path = fs.resolve(parent.path, child);
this.prefixLength = parent.prefixLength;
}
@ -316,7 +316,7 @@ public class File
throw new NullPointerException();
}
if (parent != null) {
if (parent.equals("")) {
if (parent.isEmpty()) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
@ -359,7 +359,7 @@ public class File
throw new NullPointerException();
}
if (parent != null) {
if (parent.path.equals("")) {
if (parent.path.isEmpty()) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
@ -426,7 +426,7 @@ public class File
if (uri.getRawQuery() != null)
throw new IllegalArgumentException("URI has a query component");
String p = uri.getPath();
if (p.equals(""))
if (p.isEmpty())
throw new IllegalArgumentException("URI path component is empty");
// Okay, now initialize

View file

@ -1201,7 +1201,7 @@ public class SecurityManager {
private static String[] getPackages(String p) {
String packages[] = null;
if (p != null && !p.equals("")) {
if (p != null && !p.isEmpty()) {
java.util.StringTokenizer tok =
new java.util.StringTokenizer(p, ",");
int n = tok.countTokens();

View file

@ -970,7 +970,7 @@ public final class System {
if (key == null) {
throw new NullPointerException("key can't be null");
}
if (key.equals("")) {
if (key.isEmpty()) {
throw new IllegalArgumentException("key can't be empty");
}
}

View file

@ -174,9 +174,9 @@ public final class Parameter implements AnnotatedElement {
*/
public String getName() {
// Note: empty strings as parameter names are now outlawed.
// The .equals("") is for compatibility with current JVM
// The .isEmpty() is for compatibility with current JVM
// behavior. It may be removed at some point.
if(name == null || name.equals(""))
if(name == null || name.isEmpty())
return "arg" + index;
else
return name;

View file

@ -241,7 +241,7 @@ class HostPortrange {
int[] parsePort(String port)
{
if (port == null || port.equals("")) {
if (port == null || port.isEmpty()) {
return defaultPort();
}
@ -260,13 +260,13 @@ class HostPortrange {
String high = port.substring(dash+1);
int l,h;
if (low.equals("")) {
if (low.isEmpty()) {
l = PORT_MIN;
} else {
l = Integer.parseInt(low);
}
if (high.equals("")) {
if (high.isEmpty()) {
h = PORT_MAX;
} else {
h = Integer.parseInt(high);

View file

@ -1009,7 +1009,7 @@ class InetAddress implements java.io.Serializable {
+ " not found ");
}
if ((host == null) || (host.equals("")) || (host.equals(" "))) {
if ((host == null) || (host.isEmpty()) || (host.equals(" "))) {
throw new UnknownHostException("Requested address "
+ addrString
+ " resolves to an invalid entry in hosts file "
@ -1046,7 +1046,7 @@ class InetAddress implements java.io.Serializable {
hostEntry = removeComments(hostEntry);
if (hostEntry.contains(host)) {
addrStr = extractHostAddr(hostEntry, host);
if ((addrStr != null) && (!addrStr.equals(""))) {
if ((addrStr != null) && (!addrStr.isEmpty())) {
addr = createAddressByteArray(addrStr);
if (inetAddresses == null) {
inetAddresses = new ArrayList<>(1);

View file

@ -305,7 +305,7 @@ public final class SocketPermission extends Permission
}
private static String getHost(String host) {
if (host.equals("")) {
if (host.isEmpty()) {
return "localhost";
} else {
/* IPv6 literal address used in this context should follow
@ -344,7 +344,7 @@ public final class SocketPermission extends Permission
throws Exception
{
if (port == null || port.equals("") || port.equals("*")) {
if (port == null || port.isEmpty() || port.equals("*")) {
return new int[] {PORT_MIN, PORT_MAX};
}
@ -358,13 +358,13 @@ public final class SocketPermission extends Permission
String high = port.substring(dash+1);
int l,h;
if (low.equals("")) {
if (low.isEmpty()) {
l = PORT_MIN;
} else {
l = Integer.parseInt(low);
}
if (high.equals("")) {
if (high.isEmpty()) {
h = PORT_MAX;
} else {
h = Integer.parseInt(high);
@ -496,7 +496,7 @@ public final class SocketPermission extends Permission
throw new NullPointerException("action can't be null");
}
if (action.equals("")) {
if (action.isEmpty()) {
throw new IllegalArgumentException("action can't be empty");
}

View file

@ -533,11 +533,11 @@ public final class URLPermission extends Permission {
String thishost = this.p.hostname();
String thathost = that.p.hostname();
if (p.wildcard() && thishost.equals("")) {
if (p.wildcard() && thishost.isEmpty()) {
// this "*" implies all others
return true;
}
if (that.p.wildcard() && thathost.equals("")) {
if (that.p.wildcard() && thathost.isEmpty()) {
// that "*" can only be implied by this "*"
return false;
}

View file

@ -437,7 +437,7 @@ public abstract class URLStreamHandler {
return u.hostAddress;
String host = u.getHost();
if (host == null || host.equals("")) {
if (host == null || host.isEmpty()) {
return null;
} else {
try {

View file

@ -2226,10 +2226,10 @@ public final class Locale implements Cloneable, Serializable {
default:
return Arrays.stream(stringList).reduce("",
(s1, s2) -> {
if (s1.equals("")) {
if (s1.isEmpty()) {
return s2;
}
if (s2.equals("")) {
if (s2.isEmpty()) {
return s1;
}
return MessageFormat.format(pattern, s1, s2);
@ -3069,7 +3069,7 @@ public final class Locale implements Cloneable, Serializable {
private static boolean isSubtagIllFormed(String subtag,
boolean isFirstSubtag) {
if (subtag.equals("") || subtag.length() > 8) {
if (subtag.isEmpty() || subtag.length() > 8) {
return true;
} else if (subtag.equals("*")) {
return false;

View file

@ -704,7 +704,7 @@ public abstract class Pack200 {
if (impl == null) {
// The first time, we must decide which class to use.
implName = GetPropertyAction.privilegedGetProperty(prop,"");
if (implName != null && !implName.equals(""))
if (implName != null && !implName.isEmpty())
impl = Class.forName(implName);
else if (PACK_PROVIDER.equals(prop))
impl = com.sun.java.util.jar.pack.PackerImpl.class;

View file

@ -1290,7 +1290,7 @@ public final class Pattern
// Construct result
int resultSize = matchList.size();
if (limit == 0)
while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
while (resultSize > 0 && matchList.get(resultSize-1).isEmpty())
resultSize--;
String[] result = new String[resultSize];
return matchList.subList(0, resultSize).toArray(result);

View file

@ -531,7 +531,7 @@ public class Cipher {
public static final Cipher getInstance(String transformation)
throws NoSuchAlgorithmException, NoSuchPaddingException
{
if ((transformation == null) || transformation.equals("")) {
if ((transformation == null) || transformation.isEmpty()) {
throw new NoSuchAlgorithmException("Null or empty transformation");
}
List<Transform> transforms = getTransforms(transformation);
@ -631,7 +631,7 @@ public class Cipher {
throws NoSuchAlgorithmException, NoSuchProviderException,
NoSuchPaddingException
{
if ((transformation == null) || transformation.equals("")) {
if ((transformation == null) || transformation.isEmpty()) {
throw new NoSuchAlgorithmException("Null or empty transformation");
}
if ((provider == null) || (provider.length() == 0)) {
@ -698,7 +698,7 @@ public class Cipher {
Provider provider)
throws NoSuchAlgorithmException, NoSuchPaddingException
{
if ((transformation == null) || transformation.equals("")) {
if ((transformation == null) || transformation.isEmpty()) {
throw new NoSuchAlgorithmException("Null or empty transformation");
}
if (provider == null) {
@ -2840,4 +2840,4 @@ public class Cipher {
sb.append(", algorithm from: ").append(getProviderName());
return sb.toString();
}
}
}

View file

@ -668,7 +668,7 @@ public class SSLParameters {
String[] tempProtocols = protocols.clone();
for (String p : tempProtocols) {
if (p == null || p.equals("")) {
if (p == null || p.isEmpty()) {
throw new IllegalArgumentException(
"An element of protocols was null/empty");
}

View file

@ -97,10 +97,10 @@ public class URLClassPath {
JAVA_VERSION = props.getProperty("java.version");
DEBUG = (props.getProperty("sun.misc.URLClassPath.debug") != null);
String p = props.getProperty("sun.misc.URLClassPath.disableJarChecking");
DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
DISABLE_JAR_CHECKING = p != null ? p.equals("true") || p.isEmpty() : false;
p = props.getProperty("jdk.net.URLClassPath.disableRestrictedPermissions");
DISABLE_ACC_CHECKING = p != null ? p.equals("true") || p.equals("") : false;
DISABLE_ACC_CHECKING = p != null ? p.equals("true") || p.isEmpty() : false;
// This property will be removed in a later release
p = props.getProperty("jdk.net.URLClassPath.disableClassPathURLCheck", "true");

View file

@ -111,7 +111,7 @@ public class URLJarFile extends JarFile {
* 'file:' URLs can be accessible through ftp.
*/
String host = url.getHost();
if (host == null || host.equals("") || host.equals("~") ||
if (host == null || host.isEmpty() || host.equals("~") ||
host.equalsIgnoreCase("localhost"))
return true;
}

View file

@ -127,7 +127,7 @@ public class Handler extends URLStreamHandler {
* Let's just make sure we DO have an Email address in the URL.
*/
boolean nogood = false;
if (file == null || file.equals(""))
if (file == null || file.isEmpty())
nogood = true;
else {
boolean allwhites = true;

View file

@ -1608,7 +1608,7 @@ public class PolicyFile extends java.security.Policy {
if (u.getProtocol().equals("file")) {
boolean isLocalFile = false;
String host = u.getHost();
isLocalFile = (host == null || host.equals("") ||
isLocalFile = (host == null || host.isEmpty() ||
host.equals("~") || host.equalsIgnoreCase("localhost"));
if (isLocalFile) {

View file

@ -103,7 +103,7 @@ public class ConsoleCallbackHandler implements CallbackHandler {
System.err.flush();
String result = readLine();
if (result.equals("")) {
if (result.isEmpty()) {
result = nc.getDefaultName();
}
@ -212,7 +212,7 @@ public class ConsoleCallbackHandler implements CallbackHandler {
prompt = "";
}
prompt = prefix + prompt;
if (!prompt.equals("")) {
if (!prompt.isEmpty()) {
System.err.println(prompt);
}

View file

@ -363,7 +363,7 @@ class DomainName {
}
private static int numLabels(String rule) {
if (rule.equals("")) {
if (rule.isEmpty()) {
return 0;
}
int len = rule.length();