From d155b8e65f88eba52807667358e8ed4aa3292f9f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 13 Jul 2015 22:48:51 +1200 Subject: Catch multiple exception types --- src/org/traccar/command/CommandType.java | 9 +++------ src/org/traccar/database/DataManager.java | 4 +--- src/org/traccar/database/QueryBuilder.java | 21 +++++++-------------- src/org/traccar/http/JsonConverter.java | 8 ++------ 4 files changed, 13 insertions(+), 29 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/command/CommandType.java b/src/org/traccar/command/CommandType.java index b5f6393b6..56596fa41 100644 --- a/src/org/traccar/command/CommandType.java +++ b/src/org/traccar/command/CommandType.java @@ -8,8 +8,7 @@ public enum CommandType implements Factory { STOP_ENGINE(NoParameterCommand.class), RESUME_ENGINE(NoParameterCommand.class); - - private Class commandClass; + private final Class commandClass; CommandType(Class commandClass) { this.commandClass = commandClass; @@ -19,10 +18,8 @@ public enum CommandType implements Factory { public Object create() { try { return commandClass.newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); + } catch (InstantiationException | IllegalAccessException error) { + throw new RuntimeException(error); } } } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 959602512..b7ecac52b 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -200,9 +200,7 @@ public class DataManager implements IdentityManager { updateLatestPosition(position); - } catch (SQLException error) { - Log.warning(error); - } catch (ParseException error) { + } catch (SQLException | ParseException error) { Log.warning(error); } } diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 88183f525..583a18539 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -264,8 +264,7 @@ public class QueryBuilder { } else if (method.getReturnType().equals(byte[].class)) { setBytes(name, (byte[]) method.invoke(object)); } - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } } @@ -328,8 +327,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, resultSet.getBoolean(name)); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); @@ -339,8 +337,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, resultSet.getInt(name)); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); @@ -350,8 +347,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, resultSet.getLong(name)); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); @@ -361,8 +357,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, resultSet.getDouble(name)); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); @@ -372,8 +367,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, resultSet.getString(name)); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); @@ -383,8 +377,7 @@ public class QueryBuilder { public void process(T object, ResultSet resultSet) throws SQLException { try { method.invoke(object, new Date(resultSet.getTimestamp(name).getTime())); - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } }); diff --git a/src/org/traccar/http/JsonConverter.java b/src/org/traccar/http/JsonConverter.java index d658ef7d6..d8773ec1f 100644 --- a/src/org/traccar/http/JsonConverter.java +++ b/src/org/traccar/http/JsonConverter.java @@ -30,7 +30,6 @@ import javax.json.JsonArrayBuilder; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; import javax.json.JsonValue; - import org.traccar.model.Factory; public class JsonConverter { @@ -89,9 +88,7 @@ public class JsonConverter { populateObject(json.getJsonObject(name), nestedObject); method.invoke(object, nestedObject); } - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { - } catch (InstantiationException e) { + } catch (IllegalAccessException | InvocationTargetException | InstantiationException error) { } } } @@ -130,8 +127,7 @@ public class JsonConverter { json.add(name, dateFormat.format(value)); } } - } catch (IllegalAccessException error) { - } catch (InvocationTargetException error) { + } catch (IllegalAccessException | InvocationTargetException error) { } } } -- cgit v1.2.3