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

@ -114,7 +114,7 @@ public class ServerNotifForwarder {
// 6238731: set the default domain if no domain is set.
ObjectName nn = name;
if (name.getDomain() == null || name.getDomain().equals("")) {
if (name.getDomain() == null || name.getDomain().isEmpty()) {
try {
nn = ObjectName.getInstance(mbeanServer.getDefaultDomain(),
name.getKeyPropertyList());

View file

@ -110,7 +110,7 @@ public class ImmutableDescriptor implements Descriptor {
new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
for (Map.Entry<String, ?> entry : fields.entrySet()) {
String name = entry.getKey();
if (name == null || name.equals(""))
if (name == null || name.isEmpty())
throw new IllegalArgumentException("Empty or null field name");
if (map.containsKey(name))
throw new IllegalArgumentException("Duplicate name: " + name);
@ -166,7 +166,7 @@ public class ImmutableDescriptor implements Descriptor {
new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
for (int i = 0; i < fieldNames.length; i++) {
String name = fieldNames[i];
if (name == null || name.equals(""))
if (name == null || name.isEmpty())
throw new IllegalArgumentException("Empty or null field name");
Object old = map.put(name, fieldValues[i]);
if (old != null) {
@ -333,7 +333,7 @@ public class ImmutableDescriptor implements Descriptor {
Object[] result = new Object[fieldNames.length];
for (int i = 0; i < fieldNames.length; i++) {
String name = fieldNames[i];
if (name != null && !name.equals(""))
if (name != null && !name.isEmpty())
result[i] = getFieldValue(name);
}
return result;
@ -543,7 +543,7 @@ public class ImmutableDescriptor implements Descriptor {
}
private static void checkIllegalFieldName(String name) {
if (name == null || name.equals(""))
if (name == null || name.isEmpty())
illegal("Null or empty field name");
}

View file

@ -256,7 +256,7 @@ public class MBeanPermission extends Permission {
if (actions == null)
throw new IllegalArgumentException("MBeanPermission: " +
"actions can't be null");
if (actions.equals(""))
if (actions.isEmpty())
throw new IllegalArgumentException("MBeanPermission: " +
"actions can't be empty");
@ -279,7 +279,7 @@ public class MBeanPermission extends Permission {
throw new IllegalArgumentException("MBeanPermission name " +
"cannot be null");
if (name.equals(""))
if (name.isEmpty())
throw new IllegalArgumentException("MBeanPermission name " +
"cannot be empty");
@ -310,7 +310,7 @@ public class MBeanPermission extends Permission {
//
String on = name.substring(openingBracket + 1,
name.length() - 1);
if (on.equals(""))
if (on.isEmpty())
objectName = ObjectName.WILDCARD;
else if (on.equals("-"))
objectName = null;
@ -359,7 +359,7 @@ public class MBeanPermission extends Permission {
if (className == null || className.equals("-")) {
classNamePrefix = null;
classNameExactMatch = false;
} else if (className.equals("") || className.equals("*")) {
} else if (className.isEmpty() || className.equals("*")) {
classNamePrefix = "";
classNameExactMatch = false;
} else if (className.endsWith(".*")) {
@ -375,7 +375,7 @@ public class MBeanPermission extends Permission {
private void setMember(String member) {
if (member == null || member.equals("-"))
this.member = null;
else if (member.equals(""))
else if (member.isEmpty())
this.member = "*";
else
this.member = member;

View file

@ -443,7 +443,7 @@ public class DescriptorSupport
init(null);
for (int i=0; i < fields.length; i++) {
if ((fields[i] == null) || (fields[i].equals(""))) {
if ((fields[i] == null) || (fields[i].isEmpty())) {
continue;
}
int eq_separator = fields[i].indexOf('=');
@ -467,7 +467,7 @@ public class DescriptorSupport
fieldValue = fields[i].substring(eq_separator+1);
}
if (fieldName.equals("")) {
if (fieldName.isEmpty()) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Descriptor(String... fields) " +
@ -500,7 +500,7 @@ public class DescriptorSupport
public synchronized Object getFieldValue(String fieldName)
throws RuntimeOperationsException {
if ((fieldName == null) || (fieldName.equals(""))) {
if ((fieldName == null) || (fieldName.isEmpty())) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Illegal arguments: null field name");
@ -522,7 +522,7 @@ public class DescriptorSupport
throws RuntimeOperationsException {
// field name cannot be null or empty
if ((fieldName == null) || (fieldName.equals(""))) {
if ((fieldName == null) || (fieldName.isEmpty())) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Illegal arguments: null or empty field name");
@ -664,7 +664,7 @@ public class DescriptorSupport
responseFields[i++] = value;
} else {
for (i=0; i < fieldNames.length; i++) {
if ((fieldNames[i] == null) || (fieldNames[i].equals(""))) {
if ((fieldNames[i] == null) || (fieldNames[i].isEmpty())) {
responseFields[i] = null;
} else {
responseFields[i] = getFieldValue(fieldNames[i]);
@ -700,7 +700,7 @@ public class DescriptorSupport
}
for (int i=0; i < fieldNames.length; i++) {
if (( fieldNames[i] == null) || (fieldNames[i].equals(""))) {
if (( fieldNames[i] == null) || (fieldNames[i].isEmpty())) {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Null field name encountered at element " + i);
@ -733,7 +733,7 @@ public class DescriptorSupport
}
public synchronized void removeField(String fieldName) {
if ((fieldName == null) || (fieldName.equals(""))) {
if ((fieldName == null) || (fieldName.isEmpty())) {
return;
}
@ -862,7 +862,7 @@ public class DescriptorSupport
String thisDescType = (String)(getFieldValue("descriptorType"));
if ((thisName == null) || (thisDescType == null) ||
(thisName.equals("")) || (thisDescType.equals(""))) {
(thisName.isEmpty()) || (thisDescType.isEmpty())) {
return false;
}
@ -912,7 +912,7 @@ public class DescriptorSupport
private boolean validateField(String fldName, Object fldValue) {
if ((fldName == null) || (fldName.equals("")))
if ((fldName == null) || (fldName.isEmpty()))
return false;
String SfldValue = "";
boolean isAString = false;
@ -931,7 +931,7 @@ public class DescriptorSupport
fldName.equalsIgnoreCase("Class")) {
if (fldValue == null || !isAString)
return false;
if (nameOrDescriptorType && SfldValue.equals(""))
if (nameOrDescriptorType && SfldValue.isEmpty())
return false;
return true;
} else if (fldName.equalsIgnoreCase("visibility")) {

View file

@ -367,7 +367,7 @@ public class ModelMBeanInfoSupport extends MBeanInfo implements ModelMBeanInfo {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if ((inDescriptorType == null) || (inDescriptorType.equals(""))) {
if ((inDescriptorType == null) || (inDescriptorType.isEmpty())) {
inDescriptorType = "all";
}
@ -600,7 +600,7 @@ public class ModelMBeanInfoSupport extends MBeanInfo implements ModelMBeanInfo {
inDescriptor = new DescriptorSupport();
}
if ((inDescriptorType == null) || (inDescriptorType.equals(""))) {
if ((inDescriptorType == null) || (inDescriptorType.isEmpty())) {
inDescriptorType =
(String) inDescriptor.getFieldValue("descriptorType");

View file

@ -171,7 +171,7 @@ public class CompositeType extends OpenType<CompositeData> {
private static void checkForEmptyString(String[] arg, String argName) {
for (int i=0; i<arg.length; i++) {
if (arg[i].trim().equals("")) {
if (arg[i].trim().isEmpty()) {
throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
}
}

View file

@ -456,11 +456,11 @@ public class OpenMBeanAttributeInfoSupport
throw new IllegalArgumentException("OpenType cannot be null");
if (info.getName() == null ||
info.getName().trim().equals(""))
info.getName().trim().isEmpty())
throw new IllegalArgumentException("Name cannot be null or empty");
if (info.getDescription() == null ||
info.getDescription().trim().equals(""))
info.getDescription().trim().isEmpty())
throw new IllegalArgumentException("Description cannot be null or empty");
// Check and initialize defaultValue

View file

@ -124,11 +124,11 @@ public class OpenMBeanConstructorInfoSupport
// check parameters that should not be null or empty
// (unfortunately it is not done in superclass :-( ! )
//
if (name == null || name.trim().equals("")) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Argument name cannot be " +
"null or empty");
}
if (description == null || description.trim().equals("")) {
if (description == null || description.trim().isEmpty()) {
throw new IllegalArgumentException("Argument description cannot " +
"be null or empty");
}

View file

@ -163,11 +163,11 @@ public class OpenMBeanOperationInfoSupport
// check parameters that should not be null or empty
// (unfortunately it is not done in superclass :-( ! )
//
if (name == null || name.trim().equals("")) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Argument name cannot " +
"be null or empty");
}
if (description == null || description.trim().equals("")) {
if (description == null || description.trim().isEmpty()) {
throw new IllegalArgumentException("Argument description cannot " +
"be null or empty");
}

View file

@ -268,7 +268,7 @@ public abstract class OpenType<T> implements Serializable {
/* Return argValue.trim() provided argValue is neither null nor empty;
otherwise throw IllegalArgumentException. */
private static String valid(String argName, String argValue) {
if (argValue == null || (argValue = argValue.trim()).equals(""))
if (argValue == null || (argValue = argValue.trim()).isEmpty())
throw new IllegalArgumentException("Argument " + argName +
" cannot be null or empty");
return argValue;

View file

@ -165,7 +165,7 @@ public class TabularType extends OpenType<TabularData> {
*/
private static void checkForEmptyString(String[] arg, String argName) {
for (int i=0; i<arg.length; i++) {
if (arg[i].trim().equals("")) {
if (arg[i].trim().isEmpty()) {
throw new IllegalArgumentException("Argument's element "+ argName +"["+ i +"] cannot be an empty string.");
}
}

View file

@ -405,7 +405,7 @@ public class JMXConnectorFactory {
}
final String pkgs = (String) pkgsObject;
if (pkgs.trim().equals(""))
if (pkgs.trim().isEmpty())
return null;
// pkgs may not contain an empty element

View file

@ -663,7 +663,7 @@ public abstract class MappedMXBeanType {
continue;
}
if (rest.equals("") ||
if (rest.isEmpty() ||
method.getParameterTypes().length > 0 ||
type == void.class ||
rest.equals("Class")) {