Fix NPE in AssociationInstance.set(T)
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/7c6bc1b8 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/7c6bc1b8 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/7c6bc1b8 Branch: refs/heads/yeoman-work Commit: 7c6bc1b8326aafcbeb5feac13da70153e9cd78f5 Parents: 84a794d Author: Paul Merlin <[email protected]> Authored: Sun May 21 17:40:33 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Sun May 21 17:40:33 2017 +0200 ---------------------------------------------------------------------- .../polygene/runtime/association/AssociationInstance.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7c6bc1b8/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInstance.java index 6d5f6fe..551bce7 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInstance.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInstance.java @@ -27,6 +27,7 @@ import org.apache.polygene.api.association.AssociationDescriptor; import org.apache.polygene.api.association.AssociationWrapper; import org.apache.polygene.api.entity.EntityReference; import org.apache.polygene.api.identity.HasIdentity; +import org.apache.polygene.api.identity.Identity; import org.apache.polygene.api.property.Property; /** @@ -64,7 +65,10 @@ public final class AssociationInstance<T> associationInfo.checkConstraints( newValue ); // Change association - associationState.set( EntityReference.create( ((HasIdentity) newValue ).identity().get())); + Identity identity = newValue != null + ? ( (HasIdentity) newValue ).identity().get() + : null; + associationState.set( EntityReference.create( identity ) ); } @Override
