Skip to content

Commit d559d7b

Browse files
committed
Require array and object value to not be null, use empty list instead
1 parent 237ee1f commit d559d7b

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/main/java/graphql/language/AbstractNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public Map<String, String> getAdditionalData() {
5959
}
6060

6161
@SuppressWarnings("unchecked")
62-
protected <V extends @Nullable Node> V deepCopy(V nullableObj) {
62+
protected <V extends @Nullable Node> @Nullable V deepCopy(@Nullable V nullableObj) {
6363
if (nullableObj == null) {
6464
return null;
6565
}
6666
return (V) nullableObj.deepCopy();
6767
}
6868

6969
@SuppressWarnings("unchecked")
70-
protected <V extends Node> @Nullable List<V> deepCopy(@Nullable List<? extends Node> list) {
70+
protected <V extends @Nullable Node> @Nullable List<V> deepCopy(@Nullable List<? extends Node> list) {
7171
if (list == null) {
7272
return null;
7373
}

src/main/java/graphql/language/ArrayValue.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public String toString() {
9191

9292
@Override
9393
public ArrayValue deepCopy() {
94-
return new ArrayValue(deepCopy(values), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
94+
List<Value> copiedValues = deepCopy(values);
95+
return new ArrayValue(copiedValues != null ? copiedValues : emptyList(), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
9596
}
9697

9798
@Override

src/main/java/graphql/language/ObjectValue.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import graphql.util.TraversalControl;
99
import graphql.util.TraverserContext;
1010
import org.jspecify.annotations.NullMarked;
11+
import org.jspecify.annotations.NullUnmarked;
1112
import org.jspecify.annotations.Nullable;
1213

1314
import java.util.LinkedHashMap;
@@ -80,7 +81,8 @@ public boolean isEqualTo(@Nullable Node o) {
8081

8182
@Override
8283
public ObjectValue deepCopy() {
83-
return new ObjectValue(deepCopy(objectFields), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
84+
List<ObjectField> copiedFields = deepCopy(objectFields);
85+
return new ObjectValue(copiedFields != null ? copiedFields : emptyList(), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
8486
}
8587

8688

@@ -107,8 +109,9 @@ public ObjectValue transform(Consumer<Builder> builderConsumer) {
107109
return builder.build();
108110
}
109111

112+
@NullUnmarked
110113
public static final class Builder implements NodeBuilder {
111-
private @Nullable SourceLocation sourceLocation;
114+
private SourceLocation sourceLocation;
112115
private ImmutableList<ObjectField> objectFields = emptyList();
113116
private ImmutableList<Comment> comments = emptyList();
114117
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
@@ -124,7 +127,7 @@ private Builder(ObjectValue existing) {
124127
this.additionalData = new LinkedHashMap<>(existing.getAdditionalData());
125128
}
126129

127-
public Builder sourceLocation(@Nullable SourceLocation sourceLocation) {
130+
public Builder sourceLocation(SourceLocation sourceLocation) {
128131
this.sourceLocation = sourceLocation;
129132
return this;
130133
}

0 commit comments

Comments
 (0)