Skip to content

Commit

Permalink
Collapse identical catch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicofisi authored and bensku committed Jul 5, 2018
1 parent 5670c1e commit 78f1b1a
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 126 deletions.
12 changes: 3 additions & 9 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,7 @@ public static boolean methodExists(final Class<?> c, final String methodName, fi
try {
c.getDeclaredMethod(methodName, parameterTypes);
return true;
} catch (final NoSuchMethodException e) {
return false;
} catch (final SecurityException e) {
} catch (final NoSuchMethodException | SecurityException e) {
return false;
}
}
Expand All @@ -714,9 +712,7 @@ public static boolean methodExists(final Class<?> c, final String methodName, fi
try {
final Method m = c.getDeclaredMethod(methodName, parameterTypes);
return m.getReturnType() == returnType;
} catch (final NoSuchMethodException e) {
return false;
} catch (final SecurityException e) {
} catch (final NoSuchMethodException | SecurityException e) {
return false;
}
}
Expand All @@ -732,9 +728,7 @@ public static boolean fieldExists(final Class<?> c, final String fieldName) {
try {
c.getDeclaredField(fieldName);
return true;
} catch (final NoSuchFieldException e) {
return false;
} catch (final SecurityException e) {
} catch (final NoSuchFieldException | SecurityException e) {
return false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/skript/SkriptAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ public File getFile() {
getFile.setAccessible(true);
file = (File) getFile.invoke(plugin);
return file;
} catch (final NoSuchMethodException e) {
Skript.outdatedError(e);
} catch (final IllegalArgumentException e) {
} catch (final NoSuchMethodException | IllegalArgumentException e) {
Skript.outdatedError(e);
} catch (final IllegalAccessException e) {
assert false;
Expand Down
28 changes: 7 additions & 21 deletions src/main/java/ch/njol/skript/bukkitutil/HealthUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ public static double getHealth(final Damageable e) {
return e.getHealth() / 2;
try {
return ((Number) getHealth.invoke(e)).doubleValue() / 2;
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
return 0;
}
Expand All @@ -88,12 +86,10 @@ public static void setHealth(final Damageable e, final double health) {
}
try {
setHealth.invoke(e, (int) Math.round(Math2.fit(0, health, getMaxHealth(e)) * 2));
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
}

Expand All @@ -107,12 +103,10 @@ public static double getMaxHealth(final Damageable e) {
return e.getMaxHealth() / 2;
try {
return ((Number) getMaxHealth.invoke(e)).doubleValue() / 2;
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
return 0;
}
Expand All @@ -129,12 +123,10 @@ public static void setMaxHealth(final Damageable e, final double health) {
}
try {
setMaxHealth.invoke(e, Math.max(1, (int) Math.round(health * 2)));
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
}

Expand All @@ -157,12 +149,10 @@ public static void damage(final Damageable e, final double d) {
}
try {
damage.invoke(e, (int) Math.round(event.getDamage()));
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
}
/**
Expand Down Expand Up @@ -196,12 +186,10 @@ public static double getDamage(final EntityDamageEvent e) {
return e.getDamage() / 2;
try {
return ((Number) getDamage.invoke(e)).doubleValue() / 2;
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
return 0;
}
Expand All @@ -219,12 +207,10 @@ public static void setDamage(final EntityDamageEvent e, final double damage) {
}
try {
setDamage.invoke(e, (int) Math.round(damage * 2));
} catch (final IllegalAccessException ex) {
} catch (final IllegalAccessException | InvocationTargetException ex) {
Skript.exception(ex);
} catch (final IllegalArgumentException ex) {
Skript.outdatedError(ex);
} catch (final InvocationTargetException ex) {
Skript.exception(ex);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public static Collection<? extends Player> getOnlinePlayers() {
return ImmutableList.copyOf((Collection<? extends Player>) o);
else
return Arrays.asList(((Player[]) o).clone());
} catch (final IllegalAccessException e) {
Skript.outdatedError(e);
} catch (final IllegalArgumentException e) {
} catch (final IllegalAccessException | IllegalArgumentException e) {
Skript.outdatedError(e);
} catch (final InvocationTargetException e) {
Skript.exception(e);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/ch/njol/skript/bukkitutil/ProjectileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public static Object getShooter(final @Nullable Projectile p) {
return null;
try {
return getShooter.invoke(p);
} catch (final IllegalAccessException e) {
assert false;
return null;
} catch (final IllegalArgumentException e) {
} catch (final IllegalAccessException | IllegalArgumentException e) {
assert false;
return null;
} catch (final InvocationTargetException e) {
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/ch/njol/skript/classes/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,11 @@ public <E extends T> E newInstance(final Class<E> c) {
final Constructor<E> constr = c.getDeclaredConstructor();
constr.setAccessible(true);
return constr.newInstance();
} catch (final InstantiationException e) {
throw new SkriptAPIException("Serializer of " + info.getCodeName() + " must override newInstance(), canBeInstantiated() or mustSyncDeserialization() if its class does not have a nullary constructor");
} catch (final NoSuchMethodException e) {
} catch (final InstantiationException | NoSuchMethodException e) {
throw new SkriptAPIException("Serializer of " + info.getCodeName() + " must override newInstance(), canBeInstantiated() or mustSyncDeserialization() if its class does not have a nullary constructor");
} catch (final SecurityException e) {
throw Skript.exception("Security manager present");
} catch (final IllegalArgumentException e) {
assert false;
return null;
} catch (final IllegalAccessException e) {
} catch (final IllegalArgumentException | IllegalAccessException e) {
assert false;
return null;
} catch (final InvocationTargetException e) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/skript/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private void load(final Class<?> c, final @Nullable Object o, final String path)
} else if (Option.class.isAssignableFrom(f.getType())) {
((Option<?>) f.get(o)).set(this, path);
}
} catch (final IllegalArgumentException e) {
assert false;
} catch (final IllegalAccessException e) {
} catch (final IllegalArgumentException | IllegalAccessException e) {
assert false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/skript/config/OptionSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public final <T> T get(String key) {
final Option<?> o = (Option<?>) f.get(this);
if (o.key.equals(key))
return (T) o.value();
} catch (final IllegalArgumentException e) {
assert false;
} catch (final IllegalAccessException e) {
} catch (final IllegalArgumentException | IllegalAccessException e) {
assert false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/skript/entity/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ protected EntityData deserialize(final Fields fields) throws StreamCorruptedExce
final EntityData<?> d = info.c.newInstance();
d.deserialize(fields);
return d;
} catch (final InstantiationException e) {
Skript.exception(e);
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException e) {
Skript.exception(e);
}
throw new StreamCorruptedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ protected boolean init() {
getClaim.setAccessible(true);
if (!Claim.class.isAssignableFrom(getClaim.getReturnType()))
getClaim = null;
} catch (final NoSuchMethodException e) {} catch (final SecurityException e) {}
} catch (final NoSuchMethodException | SecurityException e) {
// TODO error reporting
}
try {
claimsField = DataStore.class.getDeclaredField("claims");
claimsField.setAccessible(true);
if (!List.class.isAssignableFrom(claimsField.getType()))
claimsField = null;
} catch (final NoSuchFieldException e) {} catch (final SecurityException e) {}
} catch (final NoSuchFieldException | SecurityException e) {
// TODO error reporting
}
if (getClaim == null && claimsField == null) {
Skript.error("Skript " + Skript.getVersion() + " is not compatible with GriefPrevention " + plugin.getDescription().getVersion() + "."
+ " Please report this at http://dev.bukkit.org/bukkit-plugins/skript/tickets/ if this error occurred after you updated GriefPrevention.");
Expand All @@ -93,9 +97,7 @@ Claim getClaim(final long id) {
if (getClaim != null) {
try {
return (Claim) getClaim.invoke(plugin.dataStore, id);
} catch (final IllegalAccessException e) {
assert false : e;
} catch (final IllegalArgumentException e) {
} catch (final IllegalAccessException | IllegalArgumentException e) {
assert false : e;
} catch (final InvocationTargetException e) {
throw new RuntimeException(e.getCause());
Expand All @@ -110,9 +112,7 @@ Claim getClaim(final long id) {
if (((Claim) claim).getID() == id)
return (Claim) claim;
}
} catch (final IllegalArgumentException e) {
assert false : e;
} catch (final IllegalAccessException e) {
} catch (final IllegalArgumentException | IllegalAccessException e) {
assert false : e;
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/ch/njol/skript/lang/SkriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ private final <T extends SyntaxElement> T parse(final Iterator<? extends SyntaxE
return t;
}
}
} catch (final InstantiationException e) {
assert false;
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException e) {
assert false;
}
}
Expand Down Expand Up @@ -1234,9 +1232,7 @@ private NonNullPair<SkriptEventInfo<?>, SkriptEvent> parseEvent() {
log.printLog();
return new NonNullPair<>(info, e);
}
} catch (final InstantiationException e) {
assert false;
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException e) {
assert false;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/ch/njol/skript/util/Direction.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,7 @@ private void set(final String field, final @Nullable Double value) throws Stream
final Field f = Direction.class.getDeclaredField(field);
f.setAccessible(true); // required for final fields
f.set(this, value);
} catch (final IllegalArgumentException e) {
assert false : e;
} catch (final IllegalAccessException e) {
assert false : e;
} catch (final NoSuchFieldException e) {
} catch (final IllegalArgumentException | NoSuchFieldException | IllegalAccessException e) {
assert false : e;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/util/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public static <T> T callSync(final Callable<T> c, final Plugin p) {
}
} catch (final ExecutionException e) {
Skript.exception(e);
} catch (final CancellationException e) {} catch (final ThreadDeath e) {}// server shutting down
} catch (final CancellationException | ThreadDeath e) {
} // server shutting down
return null;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/ch/njol/yggdrasil/Fields.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ public Fields(final Object o, @Nullable final Yggdrasil yggdrasil) throws NotSer
assert f != null;
try {
fields.put(Yggdrasil.getID(f), new FieldContext(f, o));
} catch (final IllegalArgumentException e) {
assert false;
} catch (final IllegalAccessException e) {
} catch (final IllegalArgumentException | IllegalAccessException e) {
assert false;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/ch/njol/yggdrasil/JRESerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ public boolean canBeInstantiated(Class<? extends Object> c){
public <T> T newInstance(final Class<T> c) {
try {
return c.newInstance();
} catch (final InstantiationException e) { // all collections handled here have public nullary constructors
e.printStackTrace();
assert false;
return null;
} catch (final IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException e) { // all collections handled here have public nullary constructors
e.printStackTrace();
assert false;
return null;
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/ch/njol/yggdrasil/Yggdrasil.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ public final boolean isSerializable(final Class<?> c) {
try {
return c.isPrimitive() || c == Object.class || (Enum.class.isAssignableFrom(c) || PseudoEnum.class.isAssignableFrom(c)) && getIDNoError(c) != null ||
((YggdrasilSerializable.class.isAssignableFrom(c) || getSerializer(c) != null) && newInstance(c) != c);// whatever, just make true out if it (null is a valid return value)
} catch (final StreamCorruptedException e) { // thrown by newInstance if the class does not provide a correct constructor or is abstract
return false;
} catch (final NotSerializableException e) {
} catch (final StreamCorruptedException | NotSerializableException e) { // thrown by newInstance if the class does not provide a correct constructor or is abstract
return false;
}
}
Expand Down Expand Up @@ -335,11 +333,7 @@ final Object newInstance(final Class<?> c) throws StreamCorruptedException, NotS
throw new StreamCorruptedException("Cannot create an instance of " + c + " because the security manager didn't allow it");
} catch (final InstantiationException e) {
throw new StreamCorruptedException("Cannot create an instance of " + c + " because it is abstract");
} catch (final IllegalAccessException e) {
e.printStackTrace();
assert false;
return null;
} catch (final IllegalArgumentException e) {
} catch (final IllegalAccessException | IllegalArgumentException e) {
e.printStackTrace();
assert false;
return null;
Expand Down
22 changes: 2 additions & 20 deletions src/main/java/ch/njol/yggdrasil/util/JREFieldHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,7 @@ public boolean incompatibleField(final Object o, final Field f, final FieldConte
while (i < l)
array[i++] = null;
}
} catch (final IllegalArgumentException e) {
throw new YggdrasilException(e);
} catch (final IllegalAccessException e) {
throw new YggdrasilException(e);
} catch (final UnsupportedOperationException e) {
throw new YggdrasilException(e);
} catch (final ClassCastException e) {
throw new YggdrasilException(e);
} catch (final NullPointerException e) {
throw new YggdrasilException(e);
} catch (final IllegalStateException e) {
} catch (final IllegalArgumentException | IllegalStateException | NullPointerException | ClassCastException | UnsupportedOperationException | IllegalAccessException e) {
throw new YggdrasilException(e);
}
} else if (value instanceof Map) {
Expand All @@ -118,15 +108,7 @@ public boolean incompatibleField(final Object o, final Field f, final FieldConte
m.putAll((Map) value);
return true;
}
} catch (final IllegalArgumentException e) {
throw new YggdrasilException(e);
} catch (final IllegalAccessException e) {
throw new YggdrasilException(e);
} catch (final UnsupportedOperationException e) {
throw new YggdrasilException(e);
} catch (final ClassCastException e) {
throw new YggdrasilException(e);
} catch (final NullPointerException e) {
} catch (final IllegalArgumentException | NullPointerException | ClassCastException | UnsupportedOperationException | IllegalAccessException e) {
throw new YggdrasilException(e);
}
}
Expand Down
Loading

0 comments on commit 78f1b1a

Please sign in to comment.