Skip to content

Commit 6fe11d3

Browse files
committed
Specify nullness for graphql.schema.idl classes
1 parent a25f93b commit 6fe11d3

File tree

9 files changed

+39
-18
lines changed

9 files changed

+39
-18
lines changed

src/main/java/graphql/Assert.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package graphql;
22

3+
import org.jspecify.annotations.NullMarked;
4+
import org.jspecify.annotations.Nullable;
5+
36
import java.util.Collection;
47
import java.util.function.Supplier;
58
import java.util.regex.Pattern;
@@ -8,66 +11,67 @@
811

912
@SuppressWarnings("TypeParameterUnusedInFormals")
1013
@Internal
14+
@NullMarked
1115
public class Assert {
1216

13-
public static <T> T assertNotNullWithNPE(T object, Supplier<String> msg) {
17+
public static <T> T assertNotNullWithNPE(@Nullable T object, Supplier<String> msg) {
1418
if (object != null) {
1519
return object;
1620
}
1721
throw new NullPointerException(msg.get());
1822
}
1923

20-
public static <T> T assertNotNull(T object) {
24+
public static <T> T assertNotNull(@Nullable T object) {
2125
if (object != null) {
2226
return object;
2327
}
2428
return throwAssert("Object required to be not null");
2529
}
2630

27-
public static <T> T assertNotNull(T object, Supplier<String> msg) {
31+
public static <T> T assertNotNull(@Nullable T object, Supplier<String> msg) {
2832
if (object != null) {
2933
return object;
3034
}
3135
return throwAssert(msg.get());
3236
}
3337

34-
public static <T> T assertNotNull(T object, String constantMsg) {
38+
public static <T> T assertNotNull(@Nullable T object, String constantMsg) {
3539
if (object != null) {
3640
return object;
3741
}
3842
return throwAssert(constantMsg);
3943
}
4044

41-
public static <T> T assertNotNull(T object, String msgFmt, Object arg1) {
45+
public static <T> T assertNotNull(@Nullable T object, String msgFmt, Object arg1) {
4246
if (object != null) {
4347
return object;
4448
}
4549
return throwAssert(msgFmt, arg1);
4650
}
4751

48-
public static <T> T assertNotNull(T object, String msgFmt, Object arg1, Object arg2) {
52+
public static <T> T assertNotNull(@Nullable T object, String msgFmt, Object arg1, Object arg2) {
4953
if (object != null) {
5054
return object;
5155
}
5256
return throwAssert(msgFmt, arg1, arg2);
5357
}
5458

55-
public static <T> T assertNotNull(T object, String msgFmt, Object arg1, Object arg2, Object arg3) {
59+
public static <T> T assertNotNull(@Nullable T object, String msgFmt, Object arg1, Object arg2, Object arg3) {
5660
if (object != null) {
5761
return object;
5862
}
5963
return throwAssert(msgFmt, arg1, arg2, arg3);
6064
}
6165

6266

63-
public static <T> void assertNull(T object, Supplier<String> msg) {
67+
public static <T> void assertNull(@Nullable T object, Supplier<String> msg) {
6468
if (object == null) {
6569
return;
6670
}
6771
throwAssert(msg.get());
6872
}
6973

70-
public static <T> void assertNull(T object) {
74+
public static <T> void assertNull(@Nullable T object) {
7175
if (object == null) {
7276
return;
7377
}
@@ -86,14 +90,14 @@ public static <T> T assertShouldNeverHappen() {
8690
return throwAssert("Internal error: should never happen");
8791
}
8892

89-
public static <T> Collection<T> assertNotEmpty(Collection<T> collection) {
93+
public static <T> Collection<T> assertNotEmpty(@Nullable Collection<T> collection) {
9094
if (collection == null || collection.isEmpty()) {
9195
throwAssert("collection must be not null and not empty");
9296
}
9397
return collection;
9498
}
9599

96-
public static <T> Collection<T> assertNotEmpty(Collection<T> collection, Supplier<String> msg) {
100+
public static <T> Collection<T> assertNotEmpty(@Nullable Collection<T> collection, Supplier<String> msg) {
97101
if (collection == null || collection.isEmpty()) {
98102
throwAssert(msg.get());
99103
}
@@ -196,14 +200,14 @@ public static void assertFalse(boolean condition, String msgFmt, Object arg1, Ob
196200
*
197201
* @return the name if valid, or AssertException if invalid.
198202
*/
199-
public static String assertValidName(String name) {
203+
public static String assertValidName(@Nullable String name) {
200204
if (name != null && !name.isEmpty() && validNamePattern.matcher(name).matches()) {
201205
return name;
202206
}
203207
return throwAssert(invalidNameErrorMessage, name);
204208
}
205209

206-
private static <T> T throwAssert(String format, Object... args) {
210+
private static <T> T throwAssert(String format, @Nullable Object... args) {
207211
throw new AssertException(format(format, args));
208212
}
209213
}

src/main/java/graphql/schema/idl/FieldWiringEnvironment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import graphql.schema.GraphQLAppliedDirective;
77
import graphql.schema.GraphQLDirective;
88
import graphql.schema.GraphQLOutputType;
9+
import org.jspecify.annotations.NullMarked;
910

1011
import java.util.List;
1112

1213
@PublicApi
14+
@NullMarked
1315
public class FieldWiringEnvironment extends WiringEnvironment {
1416

1517
private final FieldDefinition fieldDefinition;
@@ -46,4 +48,4 @@ public List<GraphQLDirective> getDirectives() {
4648
public List<GraphQLAppliedDirective> getAppliedDirectives() {
4749
return appliedDirectives;
4850
}
49-
}
51+
}

src/main/java/graphql/schema/idl/InterfaceWiringEnvironment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import graphql.PublicApi;
44
import graphql.language.InterfaceTypeDefinition;
5+
import org.jspecify.annotations.NullMarked;
56

67
@PublicApi
8+
@NullMarked
79
public class InterfaceWiringEnvironment extends WiringEnvironment {
810

911
private final InterfaceTypeDefinition interfaceTypeDefinition;
@@ -16,4 +18,4 @@ public class InterfaceWiringEnvironment extends WiringEnvironment {
1618
public InterfaceTypeDefinition getInterfaceTypeDefinition() {
1719
return interfaceTypeDefinition;
1820
}
19-
}
21+
}

src/main/java/graphql/schema/idl/ScalarInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import graphql.Scalars;
77
import graphql.language.ScalarTypeDefinition;
88
import graphql.schema.GraphQLScalarType;
9+
import org.jspecify.annotations.NullMarked;
910

1011
import java.util.List;
1112
import java.util.Map;
@@ -14,6 +15,7 @@
1415
* Info on all the standard scalar objects provided by graphql-java
1516
*/
1617
@PublicApi
18+
@NullMarked
1719
public class ScalarInfo {
1820

1921
/**

src/main/java/graphql/schema/idl/ScalarWiringEnvironment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import graphql.PublicApi;
44
import graphql.language.ScalarTypeDefinition;
55
import graphql.language.ScalarTypeExtensionDefinition;
6+
import org.jspecify.annotations.NullMarked;
67

78
import java.util.List;
89

910
@PublicApi
11+
@NullMarked
1012
public class ScalarWiringEnvironment extends WiringEnvironment {
1113

1214
private final ScalarTypeDefinition scalarTypeDefinition;

src/main/java/graphql/schema/idl/SchemaParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import graphql.parser.ParserOptions;
1313
import graphql.schema.idl.errors.NonSDLDefinitionError;
1414
import graphql.schema.idl.errors.SchemaProblem;
15+
import org.jspecify.annotations.NullMarked;
16+
import org.jspecify.annotations.Nullable;
1517

1618
import java.io.File;
1719
import java.io.IOException;
@@ -32,6 +34,7 @@
3234
* definitions ready to be placed into {@link SchemaGenerator} say
3335
*/
3436
@PublicApi
37+
@NullMarked
3538
public class SchemaParser {
3639

3740
/**
@@ -87,7 +90,7 @@ public TypeDefinitionRegistry parse(Reader reader) throws SchemaProblem {
8790
*
8891
* @throws SchemaProblem if there are problems compiling the schema definitions
8992
*/
90-
public TypeDefinitionRegistry parse(Reader reader, ParserOptions parserOptions) throws SchemaProblem {
93+
public TypeDefinitionRegistry parse(Reader reader, @Nullable ParserOptions parserOptions) throws SchemaProblem {
9194
try (Reader input = reader) {
9295
return parseImpl(input, parserOptions);
9396
} catch (IOException e) {
@@ -113,7 +116,7 @@ public TypeDefinitionRegistry parseImpl(Reader schemaInput) {
113116
return parseImpl(schemaInput, null);
114117
}
115118

116-
private TypeDefinitionRegistry parseImpl(Reader schemaInput, ParserOptions parseOptions) {
119+
private TypeDefinitionRegistry parseImpl(Reader schemaInput, @Nullable ParserOptions parseOptions) {
117120
try {
118121
if (parseOptions == null) {
119122
parseOptions = ParserOptions.getDefaultSdlParserOptions();

src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import graphql.schema.idl.errors.SchemaRedefinitionError;
2828
import graphql.schema.idl.errors.TypeRedefinitionError;
2929
import graphql.util.FpKit;
30+
import org.jspecify.annotations.NullMarked;
3031

3132
import java.io.Serializable;
3233
import java.util.ArrayList;
@@ -49,6 +50,7 @@
4950
*/
5051
@SuppressWarnings("rawtypes")
5152
@PublicApi
53+
@NullMarked
5254
public class TypeDefinitionRegistry implements Serializable {
5355

5456
private final Map<String, List<ObjectTypeExtensionDefinition>> objectTypeExtensions = new LinkedHashMap<>();

src/main/java/graphql/schema/idl/UnionWiringEnvironment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import graphql.PublicApi;
44
import graphql.language.UnionTypeDefinition;
5+
import org.jspecify.annotations.NullMarked;
56

67
@PublicApi
8+
@NullMarked
79
public class UnionWiringEnvironment extends WiringEnvironment {
810

911
private final UnionTypeDefinition unionTypeDefinition;
@@ -16,4 +18,4 @@ public class UnionWiringEnvironment extends WiringEnvironment {
1618
public UnionTypeDefinition getUnionTypeDefinition() {
1719
return unionTypeDefinition;
1820
}
19-
}
21+
}

src/main/java/graphql/schema/idl/WiringEnvironment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
import graphql.PublicApi;
5+
import org.jspecify.annotations.NullMarked;
56

67
@PublicApi
8+
@NullMarked
79
abstract class WiringEnvironment {
810

911
private final TypeDefinitionRegistry registry;

0 commit comments

Comments
 (0)