Skip to content

Commit

Permalink
Use Multi-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Nov 20, 2023
1 parent 7e1307e commit 5972133
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 43 deletions.
5 changes: 1 addition & 4 deletions src/com/sun/jna/CallbackReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ private Object invokeCallback(Object[] args) {
try {
result = convertResult(callbackMethod.invoke(cb, callbackArgs));
}
catch (IllegalArgumentException e) {
Native.getCallbackExceptionHandler().uncaughtException(cb, e);
}
catch (IllegalAccessException e) {
catch (IllegalArgumentException | IllegalAccessException e) {
Native.getCallbackExceptionHandler().uncaughtException(cb, e);
}
catch (InvocationTargetException e) {
Expand Down
18 changes: 1 addition & 17 deletions src/com/sun/jna/Klass.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,7 @@ private Klass() {
public static <T> T newInstance(Class<T> klass) {
try {
return klass.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException e) {
String msg = "Can't create an instance of " + klass
+ ", requires a public no-arg constructor: " + e;
throw new IllegalArgumentException(msg, e);
} catch (IllegalArgumentException e) {
String msg = "Can't create an instance of " + klass
+ ", requires a public no-arg constructor: " + e;
throw new IllegalArgumentException(msg, e);
} catch (InstantiationException e) {
String msg = "Can't create an instance of " + klass
+ ", requires a public no-arg constructor: " + e;
throw new IllegalArgumentException(msg, e);
} catch (NoSuchMethodException e) {
String msg = "Can't create an instance of " + klass
+ ", requires a public no-arg constructor: " + e;
throw new IllegalArgumentException(msg, e);
} catch (SecurityException e) {
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException e) {
String msg = "Can't create an instance of " + klass
+ ", requires a public no-arg constructor: " + e;
throw new IllegalArgumentException(msg, e);
Expand Down
6 changes: 1 addition & 5 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,7 @@ private static Charset getCharset(String encoding) {
try {
charset = Charset.forName(encoding);
}
catch(IllegalCharsetNameException e) {
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
new Object[]{encoding, e.getMessage()});
}
catch(UnsupportedCharsetException e) {
catch(IllegalCharsetNameException | UnsupportedCharsetException e) {
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
new Object[]{encoding, e.getMessage()});
}
Expand Down
6 changes: 1 addition & 5 deletions src/com/sun/jna/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,7 @@ private static void addSuppressedReflected(Throwable target, Throwable suppresse
}
try {
addSuppressedMethod.invoke(target, suppressed);
} catch (IllegalAccessException ex) {
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
} catch (IllegalArgumentException ex) {
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
} catch (InvocationTargetException ex) {
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/com/sun/jna/Structure.java
Original file line number Diff line number Diff line change
Expand Up @@ -2325,9 +2325,7 @@ static void validate(Class<? extends Structure> cls) {
try {
cls.getConstructor();
return;
}catch(NoSuchMethodException e) {
}
catch(SecurityException e) {
}catch(NoSuchMethodException | SecurityException e) {
}
throw new IllegalArgumentException("No suitable constructor found for class: " + cls.getName());
}
Expand Down
4 changes: 1 addition & 3 deletions src/com/sun/jna/VarArgsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ static VarArgsChecker create() {
} else {
return new NoVarArgsChecker();
}
} catch (NoSuchMethodException e) {
return new NoVarArgsChecker();
} catch (SecurityException e) {
} catch (NoSuchMethodException | SecurityException e) {
return new NoVarArgsChecker();
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/com/sun/jna/internal/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public static boolean isDefault(Method method) {
}
try {
return (boolean) (Boolean) METHOD_IS_DEFAULT.invoke(method);
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
} catch (IllegalArgumentException ex) {
} catch (IllegalAccessException | IllegalArgumentException ex) {
throw new RuntimeException(ex);
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
Expand Down
4 changes: 1 addition & 3 deletions test/com/sun/jna/StructureFieldOrderInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ public static void checkMethodGetFieldOrder(final Class<? extends Structure> str
final Structure structure;
try {
structure= structConstructor.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
} catch (InvocationTargetException e) {
// this is triggered by checks in Structure.getFields(), and static loadlibrary() failures
Expand Down

0 comments on commit 5972133

Please sign in to comment.