Skip to content

Commit

Permalink
fix: Handle null properties.
Browse files Browse the repository at this point in the history
When using stored procedures the transport of actual `null` properties in entities is possible and leads to a NPE. This changes checks for `NO_VALUE` respectively `NullValue` and filters literal `null` properties afterwards.

Closes #909.
  • Loading branch information
michael-simons committed Jul 8, 2022
1 parent 054d06c commit 50f7b92
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class BaseAdapter {

public Map<String, Object> convertArrayPropertiesToCollection(Map<String, Object> properties) {
return properties.entrySet().stream()
.filter(e -> e.getValue() != null)
.collect(toMap(Map.Entry::getKey, BaseAdapter::convertOrReturnSelf));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.neo4j.driver.internal.value.ListValue;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.value.NullValue;
import org.neo4j.driver.types.Entity;
import org.neo4j.driver.types.Node;
import org.neo4j.driver.types.Path;
Expand Down Expand Up @@ -111,7 +112,7 @@ public List<Object> relsInPath(Object pathValue) {

private Object toMapped(Value value) {

if (value == null) {
if (value == null || value instanceof NullValue) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.graphdb.Entity;
import org.neo4j.graphdb.Relationship;
import org.neo4j.ogm.driver.TypeSystem;
import org.neo4j.values.storable.Values;

/**
* Helper methods for embedded graph entities
Expand Down Expand Up @@ -116,7 +117,7 @@ public Map<String, Object> getAllProperties(Entity propertyContainer) {

private Object toMapped(Object value) {

if (value == null) {
if (value == null || Values.NO_VALUE == value) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.assertj.core.api.Condition;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.neo4j.ogm.domain.cineasts.minimum.Actor;
Expand Down Expand Up @@ -359,6 +360,18 @@ public void shouldWorkWithCustomConvertersOnListProperty() {
.containsExactlyInAnyOrder("foo", "bar");
}

@Test // GH-909
@Ignore("This test requires APOC on the server, as there is no other way to create literal null properties on entities.")
public void shouldDealWithArtificalNullValues() {
SingleUseEntityMapper entityMapper =
new SingleUseEntityMapper(sessionFactory.metaData(),
new ReflectionEntityInstantiator(sessionFactory.metaData()));
Movie movie = sessionFactory.openSession()
.queryForObject(Movie.class, "return apoc.create.vNode(['Movie'],{name: null, foo: null})",
Collections.emptyMap());
assertThat(movie.getName()).isNull();
}

@Test // GH-718
public void queryResultShouldHandleNodeAndRelationshipEntities() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ public Movie() {
public Movie(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

0 comments on commit 50f7b92

Please sign in to comment.