mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb
This commit is contained in:
parent
c998ead188
commit
a3df1d618e
155 changed files with 340 additions and 382 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue