Skip to content

Commit 25564f7

Browse files
committed
Add null-checks across all Ops implementations using Preconditions.checkNotNull to validate input.
1 parent 08c6b69 commit 25564f7

8 files changed

Lines changed: 272 additions & 2 deletions

File tree

aether-datafixers-codec/src/main/java/de/splatgames/aether/datafixers/codec/gson/GsonOps.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package de.splatgames.aether.datafixers.codec.gson;
2424

25+
import com.google.common.base.Preconditions;
2526
import com.google.gson.JsonArray;
2627
import com.google.gson.JsonElement;
2728
import com.google.gson.JsonNull;
@@ -131,7 +132,8 @@ public class GsonOps implements DynamicOps<JsonElement> {
131132
* @deprecated Use {@link de.splatgames.aether.datafixers.codec.json.gson.GsonOps} directly instead.
132133
*/
133134
@Deprecated(forRemoval = true, since = "0.4.0")
134-
private GsonOps(final de.splatgames.aether.datafixers.codec.json.gson.GsonOps baseOps) {
135+
private GsonOps(@NotNull final de.splatgames.aether.datafixers.codec.json.gson.GsonOps baseOps) {
136+
Preconditions.checkNotNull(baseOps, "baseOps must not be null");
135137
this.baseOps = baseOps;
136138
}
137139

@@ -194,6 +196,7 @@ public JsonElement emptyList() {
194196
*/
195197
@Override
196198
public boolean isMap(@NotNull final JsonElement value) {
199+
Preconditions.checkNotNull(value, "value must not be null");
197200
return this.baseOps.isMap(value);
198201
}
199202

@@ -209,6 +212,7 @@ public boolean isMap(@NotNull final JsonElement value) {
209212
*/
210213
@Override
211214
public boolean isList(@NotNull final JsonElement value) {
215+
Preconditions.checkNotNull(value, "value must not be null");
212216
return this.baseOps.isList(value);
213217
}
214218

@@ -225,6 +229,7 @@ public boolean isList(@NotNull final JsonElement value) {
225229
*/
226230
@Override
227231
public boolean isString(@NotNull final JsonElement value) {
232+
Preconditions.checkNotNull(value, "value must not be null");
228233
return this.baseOps.isString(value);
229234
}
230235

@@ -241,6 +246,7 @@ public boolean isString(@NotNull final JsonElement value) {
241246
*/
242247
@Override
243248
public boolean isNumber(@NotNull final JsonElement value) {
249+
Preconditions.checkNotNull(value, "value must not be null");
244250
return this.baseOps.isNumber(value);
245251
}
246252

@@ -257,6 +263,7 @@ public boolean isNumber(@NotNull final JsonElement value) {
257263
*/
258264
@Override
259265
public boolean isBoolean(@NotNull final JsonElement value) {
266+
Preconditions.checkNotNull(value, "value must not be null");
260267
return this.baseOps.isBoolean(value);
261268
}
262269

@@ -275,6 +282,7 @@ public boolean isBoolean(@NotNull final JsonElement value) {
275282
@NotNull
276283
@Override
277284
public JsonElement createString(@NotNull final String value) {
285+
Preconditions.checkNotNull(value, "value must not be null");
278286
return this.baseOps.createString(value);
279287
}
280288

@@ -405,6 +413,7 @@ public JsonElement createBoolean(final boolean value) {
405413
@NotNull
406414
@Override
407415
public JsonElement createNumeric(@NotNull final Number value) {
416+
Preconditions.checkNotNull(value, "value must not be null");
408417
return this.baseOps.createNumeric(value);
409418
}
410419

@@ -425,6 +434,7 @@ public JsonElement createNumeric(@NotNull final Number value) {
425434
@NotNull
426435
@Override
427436
public DataResult<String> getStringValue(@NotNull final JsonElement input) {
437+
Preconditions.checkNotNull(input, "input must not be null");
428438
return this.baseOps.getStringValue(input);
429439
}
430440

@@ -443,6 +453,7 @@ public DataResult<String> getStringValue(@NotNull final JsonElement input) {
443453
@NotNull
444454
@Override
445455
public DataResult<Number> getNumberValue(@NotNull final JsonElement input) {
456+
Preconditions.checkNotNull(input, "input must not be null");
446457
return this.baseOps.getNumberValue(input);
447458
}
448459

@@ -461,6 +472,7 @@ public DataResult<Number> getNumberValue(@NotNull final JsonElement input) {
461472
@NotNull
462473
@Override
463474
public DataResult<Boolean> getBooleanValue(@NotNull final JsonElement input) {
475+
Preconditions.checkNotNull(input, "input must not be null");
464476
return this.baseOps.getBooleanValue(input);
465477
}
466478

@@ -479,6 +491,7 @@ public DataResult<Boolean> getBooleanValue(@NotNull final JsonElement input) {
479491
@NotNull
480492
@Override
481493
public JsonElement createList(@NotNull final Stream<JsonElement> values) {
494+
Preconditions.checkNotNull(values, "values must not be null");
482495
return this.baseOps.createList(values);
483496
}
484497

@@ -497,6 +510,7 @@ public JsonElement createList(@NotNull final Stream<JsonElement> values) {
497510
@NotNull
498511
@Override
499512
public DataResult<Stream<JsonElement>> getList(@NotNull final JsonElement input) {
513+
Preconditions.checkNotNull(input, "input must not be null");
500514
return this.baseOps.getList(input);
501515
}
502516

@@ -516,6 +530,8 @@ public DataResult<Stream<JsonElement>> getList(@NotNull final JsonElement input)
516530
@NotNull
517531
@Override
518532
public DataResult<JsonElement> mergeToList(@NotNull final JsonElement list, @NotNull final JsonElement value) {
533+
Preconditions.checkNotNull(list, "list must not be null");
534+
Preconditions.checkNotNull(value, "value must not be null");
519535
return this.baseOps.mergeToList(list, value);
520536
}
521537

@@ -535,6 +551,8 @@ public DataResult<JsonElement> mergeToList(@NotNull final JsonElement list, @Not
535551
*/
536552
@Override
537553
public @Nullable JsonElement get(@NotNull final JsonElement value, @NotNull final String key) {
554+
Preconditions.checkNotNull(value, "value must not be null");
555+
Preconditions.checkNotNull(key, "key must not be null");
538556
return this.baseOps.get(value, key);
539557
}
540558

@@ -555,6 +573,9 @@ public DataResult<JsonElement> mergeToList(@NotNull final JsonElement list, @Not
555573
@NotNull
556574
@Override
557575
public JsonElement set(@NotNull final JsonElement value, @NotNull final String key, @NotNull final JsonElement newValue) {
576+
Preconditions.checkNotNull(value, "value must not be null");
577+
Preconditions.checkNotNull(key, "key must not be null");
578+
Preconditions.checkNotNull(newValue, "newValue must not be null");
558579
return this.baseOps.set(value, key, newValue);
559580
}
560581

@@ -573,6 +594,8 @@ public JsonElement set(@NotNull final JsonElement value, @NotNull final String k
573594
@NotNull
574595
@Override
575596
public JsonElement remove(@NotNull final JsonElement value, @NotNull final String key) {
597+
Preconditions.checkNotNull(value, "value must not be null");
598+
Preconditions.checkNotNull(key, "key must not be null");
576599
return this.baseOps.remove(value, key);
577600
}
578601

@@ -590,6 +613,8 @@ public JsonElement remove(@NotNull final JsonElement value, @NotNull final Strin
590613
*/
591614
@Override
592615
public boolean has(@NotNull final JsonElement value, @NotNull final String key) {
616+
Preconditions.checkNotNull(value, "value must not be null");
617+
Preconditions.checkNotNull(key, "key must not be null");
593618
return this.baseOps.has(value, key);
594619
}
595620

@@ -607,6 +632,7 @@ public boolean has(@NotNull final JsonElement value, @NotNull final String key)
607632
@NotNull
608633
@Override
609634
public JsonElement createMap(@NotNull final Stream<Pair<JsonElement, JsonElement>> entries) {
635+
Preconditions.checkNotNull(entries, "entries must not be null");
610636
return this.baseOps.createMap(entries);
611637
}
612638

@@ -624,6 +650,7 @@ public JsonElement createMap(@NotNull final Stream<Pair<JsonElement, JsonElement
624650
@NotNull
625651
@Override
626652
public DataResult<Stream<Pair<JsonElement, JsonElement>>> getMapEntries(@NotNull final JsonElement input) {
653+
Preconditions.checkNotNull(input, "input must not be null");
627654
return this.baseOps.getMapEntries(input);
628655
}
629656

@@ -644,6 +671,9 @@ public DataResult<Stream<Pair<JsonElement, JsonElement>>> getMapEntries(@NotNull
644671
@NotNull
645672
@Override
646673
public DataResult<JsonElement> mergeToMap(@NotNull final JsonElement map, @NotNull final JsonElement key, @NotNull final JsonElement value) {
674+
Preconditions.checkNotNull(map, "map must not be null");
675+
Preconditions.checkNotNull(key, "key must not be null");
676+
Preconditions.checkNotNull(value, "value must not be null");
647677
return this.baseOps.mergeToMap(map, key, value);
648678
}
649679

@@ -664,6 +694,8 @@ public DataResult<JsonElement> mergeToMap(@NotNull final JsonElement map, @NotNu
664694
@NotNull
665695
@Override
666696
public DataResult<JsonElement> mergeToMap(@NotNull final JsonElement map, @NotNull final JsonElement other) {
697+
Preconditions.checkNotNull(map, "map must not be null");
698+
Preconditions.checkNotNull(other, "other must not be null");
667699
return this.baseOps.mergeToMap(map, other);
668700
}
669701

@@ -685,6 +717,8 @@ public DataResult<JsonElement> mergeToMap(@NotNull final JsonElement map, @NotNu
685717
@NotNull
686718
@Override
687719
public <U> JsonElement convertTo(@NotNull final DynamicOps<U> ops, @NotNull final U input) {
720+
Preconditions.checkNotNull(ops, "ops must not be null");
721+
Preconditions.checkNotNull(input, "input must not be null");
688722
return this.baseOps.convertTo(ops, input);
689723
}
690724

0 commit comments

Comments
 (0)