Skip to content

Commit 0b23b57

Browse files
Mats-SXFlorentinD
andcommitted
Avoid NPE on ElementSchema#hasProperty
Co-authored-by: Florentin Dörre <florentin.dorre@neotechnology.com>
1 parent 2f5e978 commit 0b23b57

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

core/src/test/java/org/neo4j/gds/api/schema/NodeSchemaTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
3738
import static org.junit.jupiter.api.Assertions.assertThrows;
3839
import static org.junit.jupiter.api.Assertions.assertTrue;
3940

4041
class NodeSchemaTest {
4142

43+
@Test
44+
void handlesOutsideOfSchemaRequests() {
45+
NodeSchema empty = NodeSchema.builder().build();
46+
assertFalse(empty.hasProperty(NodeLabel.of("NotInSchema"), "notInSchemaEither"));
47+
}
48+
4249
@Test
4350
void testDefaultValues() {
4451
var label = NodeLabel.of("Foo");

core/src/test/java/org/neo4j/gds/api/schema/RelationshipSchemaTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertFalse;
3738
import static org.junit.jupiter.api.Assertions.assertThrows;
3839
import static org.junit.jupiter.api.Assertions.assertTrue;
3940

4041
class RelationshipSchemaTest {
4142

43+
@Test
44+
void handlesOutsideOfSchemaRequests() {
45+
var empty = RelationshipSchema.builder().build();
46+
assertFalse(empty.hasProperty(RelationshipType.of("NotInSchema"), "notInSchemaEither"));
47+
}
48+
4249
@Test
4350
void testDefaultValuesAndAggregation() {
4451
var relType = RelationshipType.of("BAR");

graph-schema-api/src/main/java/org/neo4j/gds/api/schema/ElementSchema.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ default boolean hasProperties(ELEMENT_IDENTIFIER elementIdentifier) {
5959

6060
@Value.Default
6161
default boolean hasProperty(ELEMENT_IDENTIFIER elementIdentifier, String propertyKey) {
62-
return (!properties().get(elementIdentifier).isEmpty() && properties().get(elementIdentifier).containsKey(propertyKey));
62+
return properties().containsKey(elementIdentifier) && (!properties()
63+
.get(elementIdentifier)
64+
.isEmpty() && properties().get(elementIdentifier).containsKey(propertyKey));
6365
}
6466

6567
@Value.Default

0 commit comments

Comments
 (0)