DATACMNS-1200 - Guard casts to primitive type in ClassGeneratingEntityInstantiator.

We now insert assertions for primitive types before passing these to the actual constructor to prevent NullPointerExceptions. We also output the index/parameter name if the parameter was null.

Original pull request: #255.
This commit is contained in:
Mark Paluch
2017-10-18 14:27:05 +02:00
committed by Oliver Gierke
parent 32536067f1
commit 78bd8fb0f7
2 changed files with 32 additions and 0 deletions

View File

@@ -264,6 +264,17 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
});
}
@Test // DATACMNS-1200
public void instantiateObjectCtor1ParamIntWithoutValue() {
doReturn(ObjectCtor1ParamInt.class).when(entity).getType();
doReturn(PreferredConstructorDiscoverer.discover(ObjectCtor1ParamInt.class))//
.when(entity).getPersistenceConstructor();
assertThatThrownBy(() -> this.instance.createInstance(entity, provider)) //
.hasCauseInstanceOf(IllegalArgumentException.class);
}
@Test // DATACMNS-578, DATACMNS-1126
@SuppressWarnings("unchecked")
public void instantiateObjectCtor7ParamsString5IntsString() {