DATAJPA-941 - Avoid causing exceptions in JPA type check.

We're now using Class.isInstance(…) in favor of .cast(…) in JpaClassUtils.isOfType(…) as the latter causes exceptions to be thrown unnecessarily.
This commit is contained in:
Oliver Gierke
2016-08-02 12:23:23 -07:00
parent 577f7dd258
commit de05e67a95

View File

@@ -31,9 +31,7 @@ abstract class JpaClassUtils {
/**
* Private constructor to prevent instantiation.
*/
private JpaClassUtils() {
}
private JpaClassUtils() {}
/**
* Returns whether the given {@link EntityManager} is of the given type.
@@ -56,10 +54,7 @@ abstract class JpaClassUtils {
Assert.hasText(typeName, "Target type name must not be null or empty!");
try {
ClassUtils.forName(typeName, classLoader).cast(source);
return true;
return ClassUtils.forName(typeName, classLoader).isInstance(source);
} catch (Exception e) {
return false;
}