DATACMNS-999 - Improve resource extensive error message concatenation.

Use simple if manually throwing the IllegalArgumentException instead of an Assert. Should be replaced with an Assert accepting Supplier when moving to Spring 5 and Java 8.

Original pull request: #198.
This commit is contained in:
Christoph Strobl
2017-02-28 17:37:14 +01:00
committed by Oliver Gierke
parent a9ed30f5dd
commit c9c94a320d

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 by the original author(s).
* Copyright 2011-2017 by the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -403,9 +403,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
public PersistentPropertyAccessor getPropertyAccessor(Object bean) {
Assert.notNull(bean, "Target bean must not be null!");
Assert.isTrue(getType().isInstance(bean),
String.format(TYPE_MISMATCH, bean.getClass().getName(), getType().getName()));
assertBeanType(bean);
return new BeanWrapper<Object>(bean);
}
@@ -418,11 +416,18 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
public IdentifierAccessor getIdentifierAccessor(Object bean) {
Assert.notNull(bean, "Target bean must not be null!");
Assert.isTrue(getType().isInstance(bean), "Target bean is not of type of the persistent entity!");
assertBeanType(bean);
return hasIdProperty() ? new IdPropertyIdentifierAccessor(this, bean) : NullReturningIdentifierAccessor.INSTANCE;
}
private void assertBeanType(Object bean) {
if (!getType().isInstance(bean)) {
throw new IllegalArgumentException(String.format(TYPE_MISMATCH, bean.getClass().getName(), getType().getName()));
}
}
/**
* A null-object implementation of {@link IdentifierAccessor} to be able to return an accessor for entities that do
* not have an identifier property.