Fixed isMatchingFieldError to properly handle empty field name
Also avoided unnecessary substring creation for field error access with wildcard. Issue: SPR-11374
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -215,10 +215,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
|
||||
@Override
|
||||
public Class<?> getFieldType(String field) {
|
||||
Object value = getFieldValue(field);
|
||||
if (value != null) {
|
||||
return value.getClass();
|
||||
}
|
||||
return null;
|
||||
return (value != null ? value.getClass() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,9 +228,10 @@ public abstract class AbstractErrors implements Errors, Serializable {
|
||||
if (field.equals(fieldError.getField())) {
|
||||
return true;
|
||||
}
|
||||
// Optimization: use charAt instead of endsWith (SPR-11304)
|
||||
// Optimization: use charAt and regionMatches instead of endsWith and startsWith (SPR-11304)
|
||||
int endIndex = field.length() - 1;
|
||||
return (field.charAt(endIndex) == '*' && fieldError.getField().startsWith(field.substring(0, endIndex)));
|
||||
return (endIndex >= 0 && field.charAt(endIndex) == '*' &&
|
||||
(endIndex == 0 || field.regionMatches(0, fieldError.getField(), 0, endIndex)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user