From 8df1fa881af65e83a037ddbdcfe626db42e9d219 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 9 Aug 2024 05:17:16 +0200 Subject: [PATCH] Collapse catch blocks --- .../congrace/exp4j/CommandlineInterpreter.java | 4 +--- .../openrocket/importt/ComponentHandler.java | 4 +--- .../core/file/rocksim/importt/BaseHandler.java | 3 +-- .../modifiers/FlightConfigurationModifier.java | 4 +--- .../modifiers/GenericModifier.java | 4 +--- .../preset/loader/DoubleUnitColumnParser.java | 1 - .../info/openrocket/core/util/Reflection.java | 14 +++----------- .../swing/gui/adaptors/DoubleModel.java | 16 ++++------------ .../swing/gui/adaptors/IntegerModel.java | 8 ++------ .../swing/gui/main/ComponentAddButtons.java | 4 +--- .../swing/gui/print/PrintController.java | 4 +--- 11 files changed, 16 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/de/congrace/exp4j/CommandlineInterpreter.java b/core/src/main/java/de/congrace/exp4j/CommandlineInterpreter.java index 78670a427..b06496366 100644 --- a/core/src/main/java/de/congrace/exp4j/CommandlineInterpreter.java +++ b/core/src/main/java/de/congrace/exp4j/CommandlineInterpreter.java @@ -35,9 +35,7 @@ public class CommandlineInterpreter { try { final PostfixExpression pe = PostfixExpression.fromInfix(string); System.out.println(pe.calculate()); - } catch (UnparsableExpressionException e) { - e.printStackTrace(); - } catch (UnknownFunctionException e) { + } catch (UnparsableExpressionException | UnknownFunctionException e) { e.printStackTrace(); } } diff --git a/core/src/main/java/info/openrocket/core/file/openrocket/importt/ComponentHandler.java b/core/src/main/java/info/openrocket/core/file/openrocket/importt/ComponentHandler.java index c217cc78e..7fa4102e0 100644 --- a/core/src/main/java/info/openrocket/core/file/openrocket/importt/ComponentHandler.java +++ b/core/src/main/java/info/openrocket/core/file/openrocket/importt/ComponentHandler.java @@ -42,9 +42,7 @@ class ComponentHandler extends AbstractElementHandler { RocketComponent c; try { c = constructor.newInstance(); - } catch (InstantiationException e) { - throw new BugException("Error constructing component.", e); - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new BugException("Error constructing component.", e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); diff --git a/core/src/main/java/info/openrocket/core/file/rocksim/importt/BaseHandler.java b/core/src/main/java/info/openrocket/core/file/rocksim/importt/BaseHandler.java index e8f5b05a9..6b3f0eaa3 100644 --- a/core/src/main/java/info/openrocket/core/file/rocksim/importt/BaseHandler.java +++ b/core/src/main/java/info/openrocket/core/file/rocksim/importt/BaseHandler.java @@ -305,8 +305,7 @@ public abstract class BaseHandler extends AbstractEle if (method != null) { method.invoke(component, material); } - } catch (IllegalAccessException ignored) { - } catch (InvocationTargetException ignored) { + } catch (IllegalAccessException | InvocationTargetException ignored) { } } diff --git a/core/src/main/java/info/openrocket/core/optimization/rocketoptimization/modifiers/FlightConfigurationModifier.java b/core/src/main/java/info/openrocket/core/optimization/rocketoptimization/modifiers/FlightConfigurationModifier.java index 637369315..9f99b4b34 100644 --- a/core/src/main/java/info/openrocket/core/optimization/rocketoptimization/modifiers/FlightConfigurationModifier.java +++ b/core/src/main/java/info/openrocket/core/optimization/rocketoptimization/modifiers/FlightConfigurationModifier.java @@ -60,9 +60,7 @@ public class FlightConfigurationModifier extends AbstractSimulationModifier { methodName = methodName.substring(0, 1).toUpperCase(Locale.ENGLISH) + methodName.substring(1); getter = new Method(modifiedClass.getMethod("get" + methodName)); setter = new Method(modifiedClass.getMethod("set" + methodName, double.class)); - } catch (SecurityException e) { - throw new BugException("Trying to find method get/set" + methodName + " in class " + modifiedClass, e); - } catch (NoSuchMethodException e) { + } catch (SecurityException | NoSuchMethodException e) { throw new BugException("Trying to find method get/set" + methodName + " in class " + modifiedClass, e); } } diff --git a/core/src/main/java/info/openrocket/core/preset/loader/DoubleUnitColumnParser.java b/core/src/main/java/info/openrocket/core/preset/loader/DoubleUnitColumnParser.java index 18d100783..2ad67453e 100644 --- a/core/src/main/java/info/openrocket/core/preset/loader/DoubleUnitColumnParser.java +++ b/core/src/main/java/info/openrocket/core/preset/loader/DoubleUnitColumnParser.java @@ -47,7 +47,6 @@ public class DoubleUnitColumnParser extends BaseUnitColumnParser { } props.put(propKey, value); - } catch (NumberFormatException nex) { } catch (IllegalArgumentException iae) { } } diff --git a/core/src/main/java/info/openrocket/core/util/Reflection.java b/core/src/main/java/info/openrocket/core/util/Reflection.java index a85c3a938..e209882a6 100644 --- a/core/src/main/java/info/openrocket/core/util/Reflection.java +++ b/core/src/main/java/info/openrocket/core/util/Reflection.java @@ -32,10 +32,7 @@ public class Reflection { public Object invoke(Object obj, Object... args) { try { return method.invoke(obj, args); - } catch (IllegalArgumentException e) { - throw new BugException("Error while invoking method '" + method + "'. " + - "Please report this as a bug.", e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException("Error while invoking method '" + method + "'. " + "Please report this as a bug.", e); } catch (InvocationTargetException e) { @@ -132,8 +129,7 @@ public class Reflection { Class c = Class.forName(name); java.lang.reflect.Method m = c.getMethod(method, params); return new Reflection.Method(m); - } catch (ClassNotFoundException ignore) { - } catch (NoSuchMethodException ignore) { + } catch (ClassNotFoundException | NoSuchMethodException ignore) { } currentclass = currentclass.getSuperclass(); @@ -174,11 +170,7 @@ public class Reflection { return constructor.newInstance(params); } } catch (ClassNotFoundException ignore) { - } catch (IllegalArgumentException e) { - throw new BugException("Construction of " + name + " failed", e); - } catch (InstantiationException e) { - throw new BugException("Construction of " + name + " failed", e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) { throw new BugException("Construction of " + name + " failed", e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); diff --git a/swing/src/main/java/info/openrocket/swing/gui/adaptors/DoubleModel.java b/swing/src/main/java/info/openrocket/swing/gui/adaptors/DoubleModel.java index 54495a291..358d60e25 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/adaptors/DoubleModel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/adaptors/DoubleModel.java @@ -792,9 +792,7 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat try { return (Double) getMethod.invoke(source) * multiplier; - } catch (IllegalArgumentException e) { - throw new BugException("Unable to invoke getMethod of " + this, e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException("Unable to invoke getMethod of " + this, e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); @@ -829,9 +827,7 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat setMethod.invoke(source, v / multiplier); // Make sure to notify all the listeners that have registered fireStateChanged(); - } catch (IllegalArgumentException e) { - throw new BugException("Unable to invoke setMethod of " + this, e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException("Unable to invoke setMethod of " + this, e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); @@ -855,9 +851,7 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat try { return (Boolean) getAutoMethod.invoke(source); - } catch (IllegalArgumentException e) { - throw new BugException("Method call failed", e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException("Method call failed", e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); @@ -881,9 +875,7 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat lastAutomatic = auto; try { setAutoMethod.invoke(source, auto); - } catch (IllegalArgumentException e) { - throw new BugException(e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException(e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); diff --git a/swing/src/main/java/info/openrocket/swing/gui/adaptors/IntegerModel.java b/swing/src/main/java/info/openrocket/swing/gui/adaptors/IntegerModel.java index d99d04294..731b6d203 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/adaptors/IntegerModel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/adaptors/IntegerModel.java @@ -201,9 +201,7 @@ public class IntegerModel implements StateChangeListener, Invalidatable { public int getValue() { try { return (Integer) getMethod.invoke(source); - } catch (IllegalArgumentException e) { - throw new BugException(e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException(e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); @@ -224,9 +222,7 @@ public class IntegerModel implements StateChangeListener, Invalidatable { try { setMethod.invoke(source, v); fireStateChanged(); - } catch (IllegalArgumentException e) { - throw new BugException(e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new BugException(e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); diff --git a/swing/src/main/java/info/openrocket/swing/gui/main/ComponentAddButtons.java b/swing/src/main/java/info/openrocket/swing/gui/main/ComponentAddButtons.java index 5d159dfe7..2cb7ae562 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/main/ComponentAddButtons.java +++ b/swing/src/main/java/info/openrocket/swing/gui/main/ComponentAddButtons.java @@ -461,9 +461,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable { RocketComponent component; try { component = (RocketComponent) constructor.newInstance(); - } catch (InstantiationException e) { - throw new BugException("Could not construct new instance of class " + constructor, e); - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new BugException("Could not construct new instance of class " + constructor, e); } catch (InvocationTargetException e) { throw Reflection.handleWrappedException(e); diff --git a/swing/src/main/java/info/openrocket/swing/gui/print/PrintController.java b/swing/src/main/java/info/openrocket/swing/gui/print/PrintController.java index b4b3ad9ee..e9091ed00 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/print/PrintController.java +++ b/swing/src/main/java/info/openrocket/swing/gui/print/PrintController.java @@ -158,9 +158,7 @@ public class PrintController { writer.close(); idoc.close(); } - catch (DocumentException e) { - } - catch (ExceptionConverter ec) { + catch (DocumentException | ExceptionConverter e) { } finally { if (outputFile != null) {