Skip to content

Commit b9589f5

Browse files
committed
Add validity assertions to Entity id accessors
1 parent df8b781 commit b9589f5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public InternalEntity( long id, String elementId, Map<String,Value> properties )
4646
@Override
4747
public long id()
4848
{
49+
assertValidId( id );
4950
return id;
5051
}
5152

@@ -142,4 +143,12 @@ public <T> Iterable<T> values( Function<Value,T> mapFunction )
142143
{
143144
return Iterables.map( properties.values(), mapFunction );
144145
}
146+
147+
protected void assertValidId( long id )
148+
{
149+
if ( id < 0 )
150+
{
151+
throw new IllegalStateException( "id not available, please use elementId instead" );
152+
}
153+
}
145154
}

driver/src/main/java/org/neo4j/driver/internal/InternalRelationship.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void setStartAndEnd( long start, String startElementId, long end, String
7272
@Override
7373
public long startNodeId()
7474
{
75+
assertValidId( start );
7576
return start;
7677
}
7778

@@ -84,6 +85,7 @@ public String startNodeElementId()
8485
@Override
8586
public long endNodeId()
8687
{
88+
assertValidId( end );
8789
return end;
8890
}
8991

0 commit comments

Comments
 (0)