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:
Juergen Hoeller
2014-01-31 12:47:08 +01:00
parent a537eb3a6a
commit 5be8301128
2 changed files with 48 additions and 30 deletions

View File

@@ -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)));
}