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

@ -1119,7 +1119,7 @@ public abstract class ClassLoader {
// true if the name is null or has the potential to be a valid binary name
private boolean checkName(String name) {
if ((name == null) || (name.length() == 0))
if ((name == null) || (name.isEmpty()))
return true;
if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
return false;

View file

@ -1409,7 +1409,7 @@ public final class Integer extends Number
boolean negative = false;
Integer result;
if (nm.length() == 0)
if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present

View file

@ -1248,7 +1248,7 @@ public final class Long extends Number
boolean negative = false;
Long result;
if (nm.length() == 0)
if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present

View file

@ -397,11 +397,11 @@ public class Package extends NamedPackage implements java.lang.reflect.Annotated
public String toString() {
String spec = versionInfo.specTitle;
String ver = versionInfo.specVersion;
if (spec != null && spec.length() > 0)
if (spec != null && !spec.isEmpty())
spec = ", " + spec;
else
spec = "";
if (ver != null && ver.length() > 0)
if (ver != null && !ver.isEmpty())
ver = ", version " + ver;
else
ver = "";

View file

@ -403,7 +403,7 @@ public class Runtime {
*/
public Process exec(String command, String[] envp, File dir)
throws IOException {
if (command.length() == 0)
if (command.isEmpty())
throw new IllegalArgumentException("Empty command");
StringTokenizer st = new StringTokenizer(command);

View file

@ -664,7 +664,7 @@ public final class String
* object.
*/
public int length() {
return value.length >> coder();
return isLatin1() ? value.length : value.length >> UTF16;
}
/**
@ -1943,8 +1943,7 @@ public final class String
* characters followed by the string argument's characters.
*/
public String concat(String str) {
int olen = str.length();
if (olen == 0) {
if (str.isEmpty()) {
return this;
}
if (coder() == str.coder()) {
@ -1956,6 +1955,7 @@ public final class String
return new String(buf, coder);
}
int len = length();
int olen = str.length();
byte[] buf = StringUTF16.newBytesFor(len + olen);
getBytes(buf, 0, UTF16);
str.getBytes(buf, len, UTF16);
@ -2316,7 +2316,7 @@ public final class String
// Construct result
int resultSize = list.size();
if (limit == 0) {
while (resultSize > 0 && list.get(resultSize - 1).length() == 0) {
while (resultSize > 0 && list.get(resultSize - 1).isEmpty()) {
resultSize--;
}
}

View file

@ -73,7 +73,7 @@ class VersionProps {
"@@VENDOR_VERSION_STRING@@";
private static final String vendor_version =
(VENDOR_VERSION_STRING.length() > 0
(!VENDOR_VERSION_STRING.isEmpty()
? " " + VENDOR_VERSION_STRING : "");
private static final String VENDOR =
@ -95,7 +95,7 @@ class VersionProps {
props.put("java.version.date", java_version_date);
props.put("java.runtime.version", java_runtime_version);
props.put("java.runtime.name", java_runtime_name);
if (VENDOR_VERSION_STRING.length() > 0)
if (!VENDOR_VERSION_STRING.isEmpty())
props.put("java.vendor.version", VENDOR_VERSION_STRING);
props.put("java.class.version", CLASSFILE_MAJOR_MINOR);

View file

@ -103,7 +103,7 @@ public final class ConstantBootstraps {
if (type != Class.class) {
throw new IllegalArgumentException();
}
if (name.length() == 0 || name.length() > 1) {
if (name.length() != 1) {
throw new IllegalArgumentException(String.format("not primitive: %s", name));
}

View file

@ -201,7 +201,7 @@ public class MethodHandles {
throw new IllegalAccessException(callerModule + " does not read " + targetModule);
if (targetModule.isNamed()) {
String pn = targetClass.getPackageName();
assert pn.length() > 0 : "unnamed package cannot be in named module";
assert !pn.isEmpty() : "unnamed package cannot be in named module";
if (!targetModule.isOpen(pn, callerModule))
throw new IllegalAccessException(targetModule + " does not open " + pn + " to " + callerModule);
}

View file

@ -62,7 +62,7 @@ final class ProxyClassesDumper {
}
try {
path = path.trim();
final Path dir = Path.of(path.length() == 0 ? "." : path);
final Path dir = Path.of(path.isEmpty() ? "." : path);
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {