Skip to content

Commit 7dba79c

Browse files
stsypanovjhoeller
authored andcommitted
Use String::isEmpty instead of "".equals(arg) when arg is not null
1 parent 4883b8a commit 7dba79c

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void setWrappedInstance(Object object, @Nullable String nestedPath, @Null
194194
this.wrappedObject = ObjectUtils.unwrapOptional(object);
195195
Assert.notNull(this.wrappedObject, "Target object must not be null");
196196
this.nestedPath = (nestedPath != null ? nestedPath : "");
197-
this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.wrappedObject);
197+
this.rootObject = (!this.nestedPath.isEmpty() ? rootObject : this.wrappedObject);
198198
this.nestedPropertyAccessors = null;
199199
this.typeConverterDelegate = new TypeConverterDelegate(this, this.wrappedObject);
200200
}

spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ else if (convertedValue instanceof String && !requiredType.isInstance(convertedV
247247
}
248248
}
249249
String trimmedValue = ((String) convertedValue).trim();
250-
if (requiredType.isEnum() && "".equals(trimmedValue)) {
250+
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
251251
// It's an empty enum identifier: reset the enum value to null.
252252
return null;
253253
}

spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected void processConstraintViolations(Set<ConstraintViolation<Object>> viol
162162
// as necessary for Hibernate Validator compatibility (non-indexed set path in field)
163163
BindingResult bindingResult = (BindingResult) errors;
164164
String nestedField = bindingResult.getNestedPath() + field;
165-
if ("".equals(nestedField)) {
165+
if (nestedField.isEmpty()) {
166166
String[] errorCodes = bindingResult.resolveMessageCodes(errorCode);
167167
ObjectError error = new ObjectError(
168168
errors.getObjectName(), errorCodes, errorArgs, violation.getMessage());

spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
4949
@Override
5050
public Boolean convert(String source) {
5151
String value = source.trim();
52-
if ("".equals(value)) {
52+
if (value.isEmpty()) {
5353
return null;
5454
}
5555
value = value.toLowerCase();

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ public String combine(String pattern1, String pattern2) {
571571
int dotPos2 = pattern2.indexOf('.');
572572
String file2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
573573
String ext2 = (dotPos2 == -1 ? "" : pattern2.substring(dotPos2));
574-
boolean ext1All = (ext1.equals(".*") || ext1.equals(""));
575-
boolean ext2All = (ext2.equals(".*") || ext2.equals(""));
574+
boolean ext1All = (ext1.equals(".*") || ext1.isEmpty());
575+
boolean ext2All = (ext2.equals(".*") || ext2.isEmpty());
576576
if (!ext1All && !ext2All) {
577577
throw new IllegalArgumentException("Cannot combine patterns: " + pattern1 + " vs " + pattern2);
578578
}

spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static boolean simpleMatch(@Nullable String pattern, @Nullable String str
5252
return str.endsWith(pattern.substring(1));
5353
}
5454
String part = pattern.substring(1, nextIndex);
55-
if ("".equals(part)) {
55+
if (part.isEmpty()) {
5656
return simpleMatch(pattern.substring(nextIndex), str);
5757
}
5858
int partIndex = str.indexOf(part);

spring-core/src/main/java/org/springframework/util/StringUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ private static Locale parseLocaleTokens(String localeString, String[] tokens) {
821821
}
822822
}
823823

824-
if ("".equals(variant) && country.startsWith("#")) {
824+
if (variant.isEmpty() && country.startsWith("#")) {
825825
variant = country;
826826
country = "";
827827
}
@@ -1192,7 +1192,7 @@ public static String[] delimitedListToStringArray(
11921192
}
11931193

11941194
List<String> result = new ArrayList<>();
1195-
if ("".equals(delimiter)) {
1195+
if (delimiter.isEmpty()) {
11961196
for (int i = 0; i < str.length(); i++) {
11971197
result.add(deleteAny(str.substring(i, i + 1), charsToDelete));
11981198
}

spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ private InjectionMetadata buildPersistenceMetadata(final Class<?> clazz) {
468468
protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) {
469469
if (this.persistenceUnits != null) {
470470
String unitNameForLookup = (unitName != null ? unitName : "");
471-
if ("".equals(unitNameForLookup)) {
471+
if (unitNameForLookup.isEmpty()) {
472472
unitNameForLookup = this.defaultPersistenceUnitName;
473473
}
474474
String jndiName = this.persistenceUnits.get(unitNameForLookup);
@@ -501,7 +501,7 @@ protected EntityManager getPersistenceContext(@Nullable String unitName, boolean
501501
Map<String, String> contexts = (extended ? this.extendedPersistenceContexts : this.persistenceContexts);
502502
if (contexts != null) {
503503
String unitNameForLookup = (unitName != null ? unitName : "");
504-
if ("".equals(unitNameForLookup)) {
504+
if (unitNameForLookup.isEmpty()) {
505505
unitNameForLookup = this.defaultPersistenceUnitName;
506506
}
507507
String jndiName = contexts.get(unitNameForLookup);
@@ -533,10 +533,10 @@ protected EntityManagerFactory findEntityManagerFactory(@Nullable String unitNam
533533
throws NoSuchBeanDefinitionException {
534534

535535
String unitNameForLookup = (unitName != null ? unitName : "");
536-
if ("".equals(unitNameForLookup)) {
536+
if (unitNameForLookup.isEmpty()) {
537537
unitNameForLookup = this.defaultPersistenceUnitName;
538538
}
539-
if (!"".equals(unitNameForLookup)) {
539+
if (!unitNameForLookup.isEmpty()) {
540540
return findNamedEntityManagerFactory(unitNameForLookup, requestingBeanName);
541541
}
542542
else {

0 commit comments

Comments
 (0)