Skip to content

Commit 1cf2b8f

Browse files
authored
Add not null preconditions for some info classes (#8235)
1 parent c245095 commit 1cf2b8f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/main/java/org/skriptlang/skript/lang/arithmetic/OperationInfo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.skriptlang.skript.lang.arithmetic;
22

33
import com.google.common.base.MoreObjects;
4+
import com.google.common.base.Preconditions;
5+
import org.jetbrains.annotations.NotNull;
46
import org.jetbrains.annotations.Nullable;
57
import org.skriptlang.skript.lang.converter.Converters;
68

@@ -16,7 +18,16 @@ public class OperationInfo<L, R, T> {
1618
private final Class<T> returnType;
1719
private final Operation<L, R, T> operation;
1820

19-
public OperationInfo(Class<L> left, Class<R> right, Class<T> returnType, Operation<L, R, T> operation) {
21+
public OperationInfo(
22+
@NotNull Class<L> left,
23+
@NotNull Class<R> right,
24+
@NotNull Class<T> returnType,
25+
@NotNull Operation<L, R, T> operation
26+
) {
27+
Preconditions.checkNotNull(left, "Cannot do arithmetic with nothing and something! (left is null)");
28+
Preconditions.checkNotNull(right, "Cannot do arithmetic with something and nothing! (right is null)");
29+
Preconditions.checkNotNull(returnType, "Cannot have nothing as the result of arithmetic! (returnType is null)");
30+
Preconditions.checkNotNull(operation, "Cannot do arithmetic with a null operation!");
2031
this.left = left;
2132
this.right = right;
2233
this.returnType = returnType;

src/main/java/org/skriptlang/skript/lang/comparator/ComparatorInfo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.skriptlang.skript.lang.comparator;
22

3+
import com.google.common.base.Preconditions;
4+
import org.jetbrains.annotations.NotNull;
5+
36
/**
47
* Holds information about a Comparator.
58
*
@@ -12,7 +15,14 @@ public final class ComparatorInfo<T1, T2> {
1215
private final Class<T2> secondType;
1316
private final Comparator<T1, T2> comparator;
1417

15-
ComparatorInfo(Class<T1> firstType, Class<T2> secondType, Comparator<T1, T2> comparator) {
18+
ComparatorInfo(
19+
@NotNull Class<T1> firstType,
20+
@NotNull Class<T2> secondType,
21+
@NotNull Comparator<T1, T2> comparator
22+
) {
23+
Preconditions.checkNotNull(firstType, "Cannot create a comparison between nothing and something! (firstType is null)");
24+
Preconditions.checkNotNull(secondType, "Cannot create a comparison between something and nothing! (secondType is null)");
25+
Preconditions.checkNotNull(comparator, "Cannot create a comparison with a null comparator!");
1626
this.firstType = firstType;
1727
this.secondType = secondType;
1828
this.comparator = comparator;

src/main/java/org/skriptlang/skript/lang/converter/ConverterInfo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.skriptlang.skript.lang.converter;
22

3+
import com.google.common.base.Preconditions;
4+
import org.jetbrains.annotations.NotNull;
5+
36
/**
47
* Holds information about a {@link Converter}.
58
*
@@ -13,7 +16,15 @@ public final class ConverterInfo<F, T> {
1316
private final Converter<F, T> converter;
1417
private final int flags;
1518

16-
public ConverterInfo(Class<F> from, Class<T> to, Converter<F, T> converter, int flags) {
19+
public ConverterInfo(
20+
@NotNull Class<F> from,
21+
@NotNull Class<T> to,
22+
@NotNull Converter<F, T> converter,
23+
int flags
24+
) {
25+
Preconditions.checkNotNull(from, "Cannot convert from nothing to something! (from is null)");
26+
Preconditions.checkNotNull(to, "Cannot convert from something to nothing! (to is null)");
27+
Preconditions.checkNotNull(converter, "Cannot convert using a null converter!");
1728
this.from = from;
1829
this.to = to;
1930
this.converter = converter;

0 commit comments

Comments
 (0)