Skip to content

Commit f208227

Browse files
authored
Fix ExprTagsOf NPE (#8512)
1 parent fc1e147 commit f208227

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/main/java/ch/njol/skript/expressions/ExprStringColor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ private List<Object> getColors(String string) {
161161
}
162162
if (selectedState == StringColor.LAST) {
163163
colors.clear();
164-
colors.add(last);
164+
if (last != null) {
165+
colors.add(last);
166+
}
165167
}
166168
return colors;
167169
}

src/main/java/ch/njol/skript/expressions/base/PropertyExpression.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ch.njol.skript.expressions.base;
22

33
import ch.njol.skript.Skript;
4+
import ch.njol.skript.SkriptAPIException;
45
import ch.njol.skript.lang.Expression;
56
import ch.njol.skript.lang.ExpressionType;
67
import ch.njol.skript.lang.SkriptParser.ParseResult;
@@ -194,6 +195,14 @@ protected final T[] get(Event event) {
194195
@Override
195196
public final T[] getAll(Event event) {
196197
T[] result = get(event, expr.getAll(event));
198+
if (result == null) {
199+
throw new SkriptAPIException("PropertyExpression must not return a null array");
200+
}
201+
for (T t : result) {
202+
if (t == null) {
203+
throw new SkriptAPIException("PropertyExpression must not return an array containing null elements");
204+
}
205+
}
197206
return Arrays.copyOf(result, result.length);
198207
}
199208

src/main/java/org/skriptlang/skript/bukkit/tags/elements/ExprTagsOf.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
5757
@Override
5858
protected Tag<?> @Nullable [] get(Event event, Object @NotNull [] source) {
5959
if (source.length == 0)
60-
return null;
60+
return new Tag[0];
6161
boolean isAny = (source[0] instanceof ItemType itemType && !itemType.isAll());
6262
Keyed[] values = TagModule.getKeyed(source[0]);
6363
if (values == null)
64-
return null;
64+
return new Tag[0];
6565
// choose single material if it's something like `any log`
6666
if (isAny) {
6767
ThreadLocalRandom random = ThreadLocalRandom.current();
@@ -110,7 +110,7 @@ public Class<Tag> getReturnType() {
110110
@Override
111111
public String toString(@Nullable Event event, boolean debug) {
112112
String registry = types.length > 1 ? "" : " " + types[0].toString();
113-
return origin.toString(datapackOnly) + registry + " tags of " + getExpr().toString(event, debug);
113+
return origin.toString(datapackOnly) + registry + " tags of " + getExpr().toString(event, debug);
114114
}
115115

116116
}

src/test/skript/tests/syntaxes/expressions/ExprFilter.sk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ test "where filter":
1919
test "input conversion":
2020
set {_strings::*} to "test1", "test2", "test3" and "4test"
2121
assert size of ({_strings::*} where [the first 4 characters of string input is "test"]) is 3 with "input was not correctly casted"
22-
assert size of ({_strings::*} where [the last string color of string input is not set]) is 0 with "input was not correctly casted"
22+
assert size of ({_strings::*} where [the last string color of string input is not set]) is 4 with "input was not correctly casted"

0 commit comments

Comments
 (0)