mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
Fix contract violations & add null checks which should close #515
This commit is contained in:
parent
f0dccbd594
commit
07ac8e41c5
@ -300,7 +300,10 @@ public final class LocalExpansionManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
final long registered = classes.stream().map(this::register).filter(Optional::isPresent)
|
||||
final long registered = classes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::register)
|
||||
.filter(Optional::isPresent)
|
||||
.count();
|
||||
|
||||
Msg.msg(sender,
|
||||
@ -321,11 +324,9 @@ public final class LocalExpansionManager implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<@NotNull List<@NotNull Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
||||
public CompletableFuture<@NotNull List<@Nullable Class<? extends PlaceholderExpansion>>> findExpansionsOnDisk() {
|
||||
return Arrays.stream(folder.listFiles((dir, name) -> name.endsWith(".jar")))
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::findExpansionInFile)
|
||||
.collect(Futures.collector());
|
||||
}
|
||||
@ -335,7 +336,14 @@ public final class LocalExpansionManager implements Listener {
|
||||
@NotNull final File file) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return FileUtil.findClass(file, PlaceholderExpansion.class);
|
||||
final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class);
|
||||
|
||||
if (expansionClass == null) {
|
||||
plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have" +
|
||||
"an a class which extends PlaceholderExpansion.");
|
||||
}
|
||||
|
||||
return expansionClass;
|
||||
} catch (final VerifyError ex) {
|
||||
plugin.getLogger().severe("Failed to load Expansion class " + file.getName() +
|
||||
" (Is a dependency missing?)");
|
||||
|
@ -20,6 +20,9 @@
|
||||
|
||||
package me.clip.placeholderapi.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@ -28,8 +31,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
@ -51,7 +52,7 @@ public class FileUtil {
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null) {
|
||||
final String name = entry.getName();
|
||||
if (name == null || name.isEmpty() || !name.endsWith(".class")) {
|
||||
if (name.isEmpty() || !name.endsWith(".class")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user