Skip to content

Commit

Permalink
nullability problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Dec 21, 2024
1 parent a7e7818 commit 556cda7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -52,8 +53,10 @@ public final class RuntimeLibPluginConfiguration {
}

private static @NotNull List<Relocation> parseRelocations() throws IOException {
List<Relocation> relocations = new ArrayList<>();
InputStream stream = ClassLoaderReader.getResource("zapper/relocations.txt");
if (stream == null)
return Collections.emptyList();
List<Relocation> relocations = new ArrayList<>();
for (String line : readAllLines(stream)) {
String[] split = line.split(":");
relocations.add(new Relocation(split[0], split[1]));
Expand All @@ -62,8 +65,10 @@ public final class RuntimeLibPluginConfiguration {
}

private static @NotNull List<Dependency> parseDependencies() {
List<Dependency> dependencies = new ArrayList<>();
InputStream stream = ClassLoaderReader.getResource("zapper/dependencies.txt");
if (stream == null)
return Collections.emptyList();
List<Dependency> dependencies = new ArrayList<>();
for (String line : readAllLines(stream)) {
String[] split = line.split(":");
dependencies.add(new Dependency(
Expand All @@ -76,8 +81,10 @@ public final class RuntimeLibPluginConfiguration {
}

private static @NotNull List<Repository> parseRepositories() {
List<Repository> repos = new ArrayList<>();
InputStream stream = ClassLoaderReader.getResource("zapper/repositories.txt");
if (stream == null)
return Collections.emptyList();
List<Repository> repos = new ArrayList<>();
for (String line : readAllLines(stream)) {
repos.add(Repository.maven(line));
}
Expand All @@ -92,7 +99,7 @@ public final class RuntimeLibPluginConfiguration {
return properties;
}

private static @SneakyThrows @NotNull List<String> readAllLines(InputStream inputStream) {
private static @SneakyThrows @NotNull List<String> readAllLines(@NotNull InputStream inputStream) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return reader.lines().collect(Collectors.toList());
}
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/revxrsal/zapper/util/ClassLoaderReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -71,7 +72,7 @@ private ClassLoaderReader() {
}

@Contract("null -> fail")
public static InputStream getResource(String fileName) {
public static @Nullable InputStream getResource(String fileName) {
if (fileName == null) {
throw new IllegalArgumentException("File name cannot be null");
} else {
Expand All @@ -84,7 +85,7 @@ public static InputStream getResource(String fileName) {
connection.setUseCaches(false);
return connection.getInputStream();
}
} catch (IOException var4) {
} catch (IOException e) {
return null;
}
}
Expand Down

0 comments on commit 556cda7

Please sign in to comment.