Fix NPE
This commit is contained in:
@@ -63,7 +63,7 @@ public class DefaultCacheRepository extends CacheRepository {
|
|||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
if (Files.isRegularFile(indexFile))
|
if (Files.isRegularFile(indexFile))
|
||||||
index = JsonUtils.GSON.fromJson(FileUtils.readText(indexFile.toFile()), Index.class);
|
index = JsonUtils.fromNonNullJson(FileUtils.readText(indexFile.toFile()), Index.class);
|
||||||
else
|
else
|
||||||
index = new Index();
|
index = new Index();
|
||||||
} catch (IOException | JsonParseException e) {
|
} catch (IOException | JsonParseException e) {
|
||||||
@@ -240,13 +240,13 @@ public class DefaultCacheRepository extends CacheRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LibraryIndex {
|
private class LibraryIndex implements Validation {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String hash;
|
private final String hash;
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
public LibraryIndex() {
|
public LibraryIndex() {
|
||||||
this(null, null, null);
|
this("", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public LibraryIndex(String name, String hash, String type) {
|
public LibraryIndex(String name, String hash, String type) {
|
||||||
@@ -255,18 +255,27 @@ public class DefaultCacheRepository extends CacheRepository {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getHash() {
|
public String getHash() {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws JsonParseException, TolerableValidationException {
|
||||||
|
if (name == null || hash == null || type == null)
|
||||||
|
throw new JsonParseException("Index.LibraryIndex.* cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ import org.jackhuang.hmcl.util.Lang;
|
|||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +95,7 @@ public final class Arguments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> parseStringArguments(List<String> arguments, Map<String, String> keys) {
|
public static List<String> parseStringArguments(List<String> arguments, Map<String, String> keys) {
|
||||||
return arguments.stream().flatMap(str -> new StringArgument(str).toString(keys, Collections.emptyMap()).stream()).collect(Collectors.toList());
|
return arguments.stream().filter(Objects::nonNull).flatMap(str -> new StringArgument(str).toString(keys, Collections.emptyMap()).stream()).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> parseArguments(List<Argument> arguments, Map<String, String> keys) {
|
public static List<String> parseArguments(List<Argument> arguments, Map<String, String> keys) {
|
||||||
@@ -107,7 +103,7 @@ public final class Arguments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> parseArguments(List<Argument> arguments, Map<String, String> keys, Map<String, Boolean> features) {
|
public static List<String> parseArguments(List<Argument> arguments, Map<String, String> keys, Map<String, Boolean> features) {
|
||||||
return arguments.stream().flatMap(arg -> arg.toString(keys, features).stream()).collect(Collectors.toList());
|
return arguments.stream().filter(Objects::nonNull).flatMap(arg -> arg.toString(keys, features).stream()).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final List<Argument> DEFAULT_JVM_ARGUMENTS;
|
public static final List<Argument> DEFAULT_JVM_ARGUMENTS;
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import org.jackhuang.hmcl.util.Immutable;
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +66,7 @@ public class RuledArgument implements Argument {
|
|||||||
public List<String> toString(Map<String, String> keys, Map<String, Boolean> features) {
|
public List<String> toString(Map<String, String> keys, Map<String, Boolean> features) {
|
||||||
if (CompatibilityRule.appliesToCurrentEnvironment(rules, features) && value != null)
|
if (CompatibilityRule.appliesToCurrentEnvironment(rules, features) && value != null)
|
||||||
return value.stream()
|
return value.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
.map(StringArgument::new)
|
.map(StringArgument::new)
|
||||||
.map(str -> str.toString(keys, features).get(0))
|
.map(str -> str.toString(keys, features).get(0))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
Reference in New Issue
Block a user