From c228d3e5d8443f19538e0abfdf0ed87e4017ab8b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 2 Aug 2016 12:23:23 -0700 Subject: [PATCH] DATAJPA-941 - Avoid causing exceptions in JPA type check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're now using Class.isInstance(…) in favor of .cast(…) in JpaClassUtils.isOfType(…) as the latter causes exceptions to be thrown unnecessarily. --- .../springframework/data/jpa/provider/JpaClassUtils.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java b/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java index 4f0eeaa64..89b2fa4a6 100644 --- a/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java +++ b/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java @@ -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; }