diff --git a/pom.xml b/pom.xml index 2473b93f59..d5483d6035 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-commons - 2.1.0.BUILD-SNAPSHOT + 2.1.0.DATACMNS-1201-SNAPSHOT Spring Data Core @@ -163,7 +163,7 @@ 1.0.1 test - + javax.interceptor javax.interceptor-api diff --git a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java index 658142a1a3..e55fd89019 100644 --- a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java +++ b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java @@ -133,7 +133,10 @@ private static boolean isClassLoaderDefineClassAvailable(PersistentEntity } private static boolean isTypeInjectable(PersistentEntity entity) { - return entity.getType().getClassLoader() != null && !entity.getType().getPackage().getName().startsWith("java"); + + Class type = entity.getType(); + return type.getClassLoader() != null + && (type.getPackage() == null || !type.getPackage().getName().startsWith("java")); } private boolean hasUniquePropertyHashCodes(PersistentEntity entity) { diff --git a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java index 8945cbeda8..f210255603 100755 --- a/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java +++ b/src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.mapping.model; import static org.assertj.core.api.Assertions.*; +import static org.junit.Assume.*; import java.lang.reflect.Constructor; import java.util.ArrayList; @@ -36,6 +36,7 @@ import org.springframework.data.mapping.context.SamplePersistentProperty; import org.springframework.data.mapping.model.subpackage.TypeInOtherPackage; import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.StringUtils; /** * Unit tests for {@link ClassGeneratingPropertyAccessorFactory} @@ -61,7 +62,8 @@ public ClassGeneratingPropertyAccessorFactoryTests(Object bean, String propertyN } @Parameters(name = "{3}") - public static List parameters() { + @SuppressWarnings("unchecked") + public static List parameters() throws ReflectiveOperationException { List parameters = new ArrayList<>(); List propertyNames = Arrays.asList("privateField", "packageDefaultField", "protectedField", "publicField", @@ -79,6 +81,11 @@ public static List parameters() { ClassGeneratingPropertyAccessorPublicType.class)); parameters.addAll(parameters(new SubtypeOfTypeInOtherPackage(), propertyNames, SubtypeOfTypeInOtherPackage.class)); + Class defaultPackageClass = (Class) Class.forName("TypeInDefaultPackage"); + + parameters + .add(new Object[] { defaultPackageClass.newInstance(), "", defaultPackageClass, "Class in default package" }); + return parameters; } @@ -94,9 +101,16 @@ private static List parameters(Object bean, List propertyNames return parameters; } + @Test // DATACMNS-1201 + public void shouldSupportGeneratedPropertyAccessors() { + assertThat(factory.isSupported(mappingContext.getRequiredPersistentEntity(bean.getClass()))).isTrue(); + } + @Test // DATACMNS-809 public void shouldSetAndGetProperty() throws Exception { + assumeTrue(StringUtils.hasText(propertyName)); + assertThat(getProperty(bean, propertyName)).satisfies(property -> { PersistentPropertyAccessor persistentPropertyAccessor = getPersistentPropertyAccessor(bean);