HHH-11294 - NPE in org.hibernate.jpa.internal.util.PersistenceUtilHelper.isInitialized(PersistentAttributeInterceptable)

This commit is contained in:
Craig Andrews 2016-11-30 14:16:13 -05:00 committed by Gail Badner
parent 77f461f8bf
commit 518d58e6b0
2 changed files with 64 additions and 16 deletions

View File

@ -94,7 +94,7 @@ public final class PersistenceUtilHelper {
@SuppressWarnings("SimplifiableIfStatement") @SuppressWarnings("SimplifiableIfStatement")
private static boolean isInitialized(PersistentAttributeInterceptable interceptable) { private static boolean isInitialized(PersistentAttributeInterceptable interceptable) {
final LazyAttributeLoadingInterceptor interceptor = extractInterceptor( interceptable ); final LazyAttributeLoadingInterceptor interceptor = extractInterceptor( interceptable );
return interceptable == null || !interceptor.hasAnyUninitializedAttributes(); return interceptable == null || interceptor == null || !interceptor.hasAnyUninitializedAttributes();
} }
private static LazyAttributeLoadingInterceptor extractInterceptor(PersistentAttributeInterceptable interceptable) { private static LazyAttributeLoadingInterceptor extractInterceptor(PersistentAttributeInterceptable interceptable) {

View File

@ -8,17 +8,20 @@ package org.hibernate.userguide.util;
import javax.persistence.spi.LoadState; import javax.persistence.spi.LoadState;
import org.junit.Test; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.jpa.internal.util.PersistenceUtilHelper; import org.hibernate.jpa.internal.util.PersistenceUtilHelper;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
* Tests for HHH-5094 and HHH-5334 * Tests for HHH-5094 and HHH-5334
* *
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public class PersistenceUtilHelperTest{ public class PersistenceUtilHelperTest {
private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache(); private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
public static class FieldAccessBean extends FieldAccessBeanBase { public static class FieldAccessBean extends FieldAccessBeanBase {
@ -50,51 +53,96 @@ public class PersistenceUtilHelperTest{
return publicAccessProperty; return publicAccessProperty;
} }
} }
@Test
@Test
public void testIsLoadedWithReferencePublicField() { public void testIsLoadedWithReferencePublicField() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "publicAccessProperty", cache ) PersistenceUtilHelper.isLoadedWithReference(
new FieldAccessBean(),
"publicAccessProperty",
cache
)
); );
} }
@Test
@Test
public void testIsLoadedWithReferencePublicMethod() { public void testIsLoadedWithReferencePublicMethod() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "publicAccessPropertyValue", cache new MethodAccessBean(),
"publicAccessPropertyValue",
cache
) )
); );
} }
@Test
@Test
public void testIsLoadedWithReferenceProtectedField() { public void testIsLoadedWithReferenceProtectedField() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "protectedAccessProperty", cache ) PersistenceUtilHelper.isLoadedWithReference(
new FieldAccessBean(),
"protectedAccessProperty",
cache
)
); );
} }
@Test
@Test
public void testIsLoadedWithReferenceProtectedMethod() { public void testIsLoadedWithReferenceProtectedMethod() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "protectedAccessPropertyValue", cache new MethodAccessBean(),
"protectedAccessPropertyValue",
cache
) )
); );
} }
@Test
@Test
public void testIsLoadedWithReferencePrivateField() { public void testIsLoadedWithReferencePrivateField() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( new FieldAccessBean(), "privateAccessProperty", cache ) PersistenceUtilHelper.isLoadedWithReference(
new FieldAccessBean(),
"privateAccessProperty",
cache
)
); );
} }
@Test
@Test
public void testIsLoadedWithReferencePrivateMethod() { public void testIsLoadedWithReferencePrivateMethod() {
assertEquals( assertEquals(
LoadState.UNKNOWN, LoadState.UNKNOWN,
PersistenceUtilHelper.isLoadedWithReference( PersistenceUtilHelper.isLoadedWithReference(
new MethodAccessBean(), "privateAccessPropertyValue", cache new MethodAccessBean(),
"privateAccessPropertyValue",
cache
)
);
}
@Test
public void testIsLoadedWithNullInterceptor() {
assertEquals(
LoadState.LOADED,
PersistenceUtilHelper.isLoaded(
new PersistentAttributeInterceptable() {
@Override
public PersistentAttributeInterceptor $$_hibernate_getInterceptor() {
return null;
}
@Override
public void $$_hibernate_setInterceptor(PersistentAttributeInterceptor interceptor) {
}
}
) )
); );
} }