From 332d9d95f4aa6a144fda434b4a97d655f405d445 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Wed, 23 Apr 2014 14:48:20 +0200 Subject: [PATCH] DATAMONGO-917 - Improve Spring 4.0 framework version detection to avoid NPEs. We now check for the presence of DefaultParameterNameDiscoverer in order to determine if we are running with a Spring version later than 4.0 since this avoids potential NullPointerExceptions in cases where the package version information is not available e.g. in cases where the application was bundled into an "uberjar" e.g. via the maven-shade-plugin. Original pull request: #173. --- .../data/mongodb/core/convert/DefaultDbRefResolver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java index d096dbdee..4a69f7d0d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java @@ -33,7 +33,6 @@ import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; import org.springframework.cglib.proxy.MethodProxy; -import org.springframework.core.SpringVersion; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.mongodb.LazyLoadingException; @@ -382,7 +381,9 @@ public class DefaultDbRefResolver implements DbRefResolver { */ private static class ObjenesisProxyEnhancer { - private static final boolean IS_SPRING_4_OR_BETTER = SpringVersion.getVersion().startsWith("4"); + private static final boolean IS_SPRING_4_OR_BETTER = ClassUtils.isPresent( + "org.springframework.core.DefaultParameterNameDiscoverer", null); + private static final InstanceCreatorStrategy INSTANCE_CREATOR; static {