Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apoc vRelationships with null values throw nullPointerExceptions in BoltEntityAdapter #909

Closed
quot-zz opened this issue Jul 7, 2022 · 1 comment
Assignees

Comments

@quot-zz
Copy link

quot-zz commented Jul 7, 2022

Creating a virtual relationship using apoc.create.vRelationship can result in objects being returned from neo4j containing null values where the properties wouldn't be passed in a normal relationship. An example of this is if a property of the virtual relationship is being mapped from a node property that is null. Trying to retrieve these virtual relationships results in a null pointer exception being thrown.

Expected Behavior

Virtual relationship properties that are returned as null from an apoc.create.vRelationship call should be mapped to null

Current Behavior

Properties containing null values are mapped as objects of type NullValue and get transformed to null when the value.asObject() method is called in the toMapped method in BoltEntityAdapter - https://github.com/neo4j/neo4j-ogm/blob/master/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltEntityAdapter.java#L121
On the subsequent line object.getClass() is called, resulting in a null pointer exception - https://github.com/neo4j/neo4j-ogm/blob/master/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltEntityAdapter.java#L122
A simple null check on object after Object object = value.asObject() should solve this problem.

Context

My current use case is trying to create virtual relationships to model data structures that require the use of intermediate nodes. For example I want to model the relationship (A)-[:r]->(B) except r also needs to reference (C). So in Neo4J I have modelled it as follows:
(A)-[:r1]->(R)-[:r2]-(B) and (R)-[:r3]->(C)

I don't want this complexity to be returned to the client so I create the virtual relationship as mentioned above, except if I am mapping properties from C to r and C does not exist they get mapped as null. This would be fine except for the null pointer exception issues mentioned.

Your Environment

  • Java version:
  • Neo4j version: 4.4.5
  • OGM Version: 3.2.35
  • OGM Transport used: Bolt
  • Neo4j Java Driver version (in case of Bolt transport): 4.3.6

Steps to Reproduce

Node

@NodeEntity
public class TestNode {

}

Relationship

@RelationshipEntity(type = "test_relationship")
public class TestRelationship {
    @StartNode
    TestNode startNode;
    @EndNode
    TestNode endNode;
    private String testField;
}

Repository


@Repository
public interface TestRelationshipRepository extends PagingAndSortingRepository<TestRelationship, String> {

    @Query("MATCH (n:TestNode) return apoc.create.vRelationship(n, 'test_relationship', {testField:null}, n)")
    Optional<TestRelationship> getRelationship();
}
@michael-simons michael-simons self-assigned this Jul 8, 2022
michael-simons added a commit that referenced this issue Jul 8, 2022
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.
@michael-simons
Copy link
Collaborator

Thanks for the report and the good analysis. The fix will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants