Don't catch exceptions thrown inside i/o (#291)

This commit is contained in:
Luck 2017-05-18 21:16:31 +01:00
parent ca1dacf2b6
commit cc907b6530
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 21 additions and 84 deletions

View File

@ -751,7 +751,7 @@ public interface PermissionHolder {
* @param server the server to filter by, can be null * @param server the server to filter by, can be null
* @param world the world to filter by, can be null * @param world the world to filter by, can be null
* @param temporary whether the query is for temporary nodes or not. * @param temporary whether the query is for temporary nodes or not.
* @deprecated in favour of {@link #removeIf(Predicate)} * @deprecated in favour of {@link #clearMatching(Predicate)}
*/ */
@Deprecated @Deprecated
void clearMetaKeys(String key, String server, String world, boolean temporary); void clearMetaKeys(String key, String server, String world, boolean temporary);

View File

@ -46,6 +46,10 @@ public class ContextManager<T> {
.expireAfterWrite(50L, TimeUnit.MILLISECONDS) .expireAfterWrite(50L, TimeUnit.MILLISECONDS)
.build(t -> calculateApplicableContext(t, MutableContextSet.create()).makeImmutable()); .build(t -> calculateApplicableContext(t, MutableContextSet.create()).makeImmutable());
public ImmutableContextSet getApplicableContext(T subject) {
return cache.get(subject);
}
private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) { private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) {
for (ContextCalculator<T> calculator : calculators) { for (ContextCalculator<T> calculator : calculators) {
try { try {
@ -58,14 +62,6 @@ public class ContextManager<T> {
return accumulator; return accumulator;
} }
public ImmutableContextSet getApplicableContext(T subject) {
return cache.get(subject);
}
public void invalidateCache(T subject){
cache.invalidate(subject);
}
public void registerCalculator(ContextCalculator<T> calculator) { public void registerCalculator(ContextCalculator<T> calculator) {
// calculators registered first should have priority (and be checked last.) // calculators registered first should have priority (and be checked last.)
calculators.add(0, calculator); calculators.add(0, calculator);
@ -83,6 +79,10 @@ public class ContextManager<T> {
return accumulator.makeImmutable(); return accumulator.makeImmutable();
} }
public void invalidateCache(T subject){
cache.invalidate(subject);
}
public int getCalculatorsSize() { public int getCalculatorsSize() {
return calculators.size(); return calculators.size();
} }

View File

@ -39,7 +39,6 @@ import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate; import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.core.NodeModel; import me.lucko.luckperms.common.core.NodeModel;
import me.lucko.luckperms.common.core.PriorityComparator;
import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.core.UserIdentifier;
import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.Track;
@ -51,7 +50,6 @@ import me.lucko.luckperms.common.storage.holder.NodeHeldPermission;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
@ -216,12 +214,7 @@ public class JSONBacking extends FlatfileBacking {
} }
if (!userFile.exists()) { if (!userFile.exists()) {
try { userFile.createNewFile();
userFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
@ -321,12 +314,7 @@ public class JSONBacking extends FlatfileBacking {
group.setNodes(nodes); group.setNodes(nodes);
return true; return true;
} else { } else {
try { groupFile.createNewFile();
groupFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
data.addProperty("name", group.getName()); data.addProperty("name", group.getName());
@ -375,12 +363,7 @@ public class JSONBacking extends FlatfileBacking {
registerFileAction("groups", groupFile); registerFileAction("groups", groupFile);
if (!groupFile.exists()) { if (!groupFile.exists()) {
try { groupFile.createNewFile();
groupFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
@ -445,12 +428,7 @@ public class JSONBacking extends FlatfileBacking {
track.setGroups(groups); track.setGroups(groups);
return true; return true;
} else { } else {
try { trackFile.createNewFile();
trackFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
data.addProperty("name", track.getName()); data.addProperty("name", track.getName());
@ -504,12 +482,7 @@ public class JSONBacking extends FlatfileBacking {
registerFileAction("tracks", trackFile); registerFileAction("tracks", trackFile);
if (!trackFile.exists()) { if (!trackFile.exists()) {
try { trackFile.createNewFile();
trackFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
@ -576,7 +549,7 @@ public class JSONBacking extends FlatfileBacking {
} }
public static JsonArray serializePermissions(Set<NodeModel> nodes) { public static JsonArray serializePermissions(Set<NodeModel> nodes) {
List<JsonObject> data = new ArrayList<>(); JsonArray arr = new JsonArray();
for (NodeModel node : nodes) { for (NodeModel node : nodes) {
JsonObject attributes = new JsonObject(); JsonObject attributes = new JsonObject();
@ -600,17 +573,7 @@ public class JSONBacking extends FlatfileBacking {
JsonObject perm = new JsonObject(); JsonObject perm = new JsonObject();
perm.add(node.getPermission(), attributes); perm.add(node.getPermission(), attributes);
data.add(perm); arr.add(perm);
}
data.sort((o1, o2) -> PriorityComparator.get().compareStrings(
Iterables.getFirst(o1.entrySet(), null).getKey(),
Iterables.getFirst(o2.entrySet(), null).getKey()
));
JsonArray arr = new JsonArray();
for (JsonObject o : data) {
arr.add(o);
} }
return arr; return arr;

View File

@ -48,7 +48,6 @@ import org.yaml.snakeyaml.Yaml;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
@ -217,12 +216,7 @@ public class YAMLBacking extends FlatfileBacking {
} }
if (!userFile.exists()) { if (!userFile.exists()) {
try { userFile.createNewFile();
userFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();
@ -322,12 +316,7 @@ public class YAMLBacking extends FlatfileBacking {
group.setNodes(nodes); group.setNodes(nodes);
return true; return true;
} else { } else {
try { groupFile.createNewFile();
groupFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();
values.put("name", group.getName()); values.put("name", group.getName());
@ -374,12 +363,7 @@ public class YAMLBacking extends FlatfileBacking {
registerFileAction("groups", groupFile); registerFileAction("groups", groupFile);
if (!groupFile.exists()) { if (!groupFile.exists()) {
try { groupFile.createNewFile();
groupFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();
@ -441,12 +425,7 @@ public class YAMLBacking extends FlatfileBacking {
track.setGroups((List<String>) values.get("groups")); track.setGroups((List<String>) values.get("groups"));
return true; return true;
} else { } else {
try { trackFile.createNewFile();
trackFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();
values.put("name", track.getName()); values.put("name", track.getName());
@ -491,12 +470,7 @@ public class YAMLBacking extends FlatfileBacking {
registerFileAction("tracks", trackFile); registerFileAction("tracks", trackFile);
if (!trackFile.exists()) { if (!trackFile.exists()) {
try { trackFile.createNewFile();
trackFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
} }
Map<String, Object> values = new LinkedHashMap<>(); Map<String, Object> values = new LinkedHashMap<>();