From 005c12fb0f9b13b17a3cc1d7c8b1686e3e1c1c24 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 22 Aug 2020 13:57:13 -0400 Subject: [PATCH] Fix build on Java 11 --- .../proxy/config/VelocityConfiguration.java | 9 ++++++++- .../proxy/plugin/VelocityPluginManager.java | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 5c2da244d..06cdc8863 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -11,6 +11,7 @@ import com.velocitypowered.api.proxy.config.ProxyConfig; import com.velocitypowered.api.util.Favicon; import com.velocitypowered.proxy.util.AddressUtil; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -393,9 +394,15 @@ public class VelocityConfiguration implements ProxyConfig { * @return the deserialized Velocity configuration * @throws IOException if we could not read from the {@code path}. */ + @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", + justification = "I looked carefully and there's no way SpotBugs is right.") public static VelocityConfiguration read(Path path) throws IOException { URL defaultConfigLocation = VelocityConfiguration.class.getClassLoader() .getResource("default-velocity.toml"); + if (defaultConfigLocation == null) { + throw new RuntimeException("Default configuration file does not exist."); + } + boolean mustResave = false; CommentedFileConfig config = CommentedFileConfig.builder(path) .defaultData(defaultConfigLocation) @@ -411,7 +418,7 @@ public class VelocityConfiguration implements ProxyConfig { // Copy over default file to tmp location try (InputStream in = defaultConfigLocation.openStream()) { - Files.copy(Objects.requireNonNull(in), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(in, tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } CommentedFileConfig defaultConfig = CommentedFileConfig.of(tmpFile, TomlFormat.instance()); defaultConfig.load(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java index 065c0d930..1a2301c38 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java @@ -18,6 +18,7 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer; import com.velocitypowered.proxy.plugin.loader.java.JavaPluginLoader; import com.velocitypowered.proxy.plugin.util.PluginDependencyUtils; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -59,6 +60,8 @@ public class VelocityPluginManager implements PluginManager { * @param directory the directory to load from * @throws IOException if we could not open the directory */ + @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", + justification = "I looked carefully and there's no way SpotBugs is right.") public void loadPlugins(Path directory) throws IOException { checkNotNull(directory, "directory"); checkArgument(directory.toFile().isDirectory(), "provided path isn't a directory"); @@ -66,8 +69,8 @@ public class VelocityPluginManager implements PluginManager { List found = new ArrayList<>(); JavaPluginLoader loader = new JavaPluginLoader(server, directory); - try (DirectoryStream stream = Files - .newDirectoryStream(directory, p -> p.toFile().isFile() && p.toString().endsWith(".jar"))) { + try (DirectoryStream stream = Files.newDirectoryStream(directory, + p -> p.toFile().isFile() && p.toString().endsWith(".jar"))) { for (Path path : stream) { try { found.add(loader.loadPluginDescription(path));