Skip to content
Snippets Groups Projects
Commit 4be841e9 authored by juanf's avatar juanf
Browse files

SSDM-3521 : Limit size of error string to 500 chars.

SVN: 36247
parent a1c30293
No related branches found
No related tags found
No related merge requests found
...@@ -70,7 +70,8 @@ public abstract class AbstractDAO extends HibernateDaoSupport ...@@ -70,7 +70,8 @@ public abstract class AbstractDAO extends HibernateDaoSupport
{ {
private static ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); private static ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
private static final int MAX_STRING_ERROR_LENGTH = 500;
protected AbstractDAO(final SessionFactory sessionFactory) protected AbstractDAO(final SessionFactory sessionFactory)
{ {
assert sessionFactory != null : "Unspecified session factory"; assert sessionFactory != null : "Unspecified session factory";
...@@ -98,6 +99,9 @@ public abstract class AbstractDAO extends HibernateDaoSupport ...@@ -98,6 +99,9 @@ public abstract class AbstractDAO extends HibernateDaoSupport
for (ConstraintViolation v : violations) for (ConstraintViolation v : violations)
{ {
Object invalidValue = v.getInvalidValue(); Object invalidValue = v.getInvalidValue();
if(invalidValue instanceof String && (((String) invalidValue).length() > MAX_STRING_ERROR_LENGTH)) {
invalidValue = String.format("%s... (complete value was %d characters)", ((String) invalidValue).substring(0, MAX_STRING_ERROR_LENGTH), ((String) invalidValue).length());
}
msg += ", " + String.format(v.getMessage(), invalidValue); msg += ", " + String.format(v.getMessage(), invalidValue);
} }
throw new DataIntegrityViolationException(msg.substring(2)); throw new DataIntegrityViolationException(msg.substring(2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment