Skip to content

Commit 3010a13

Browse files
committed
Use multi-catch
1 parent 37dc468 commit 3010a13

8 files changed

+8
-43
lines changed

src/com/sun/jna/CallbackReference.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,7 @@ private Object invokeCallback(Object[] args) {
586586
try {
587587
result = convertResult(callbackMethod.invoke(cb, callbackArgs));
588588
}
589-
catch (IllegalArgumentException e) {
590-
Native.getCallbackExceptionHandler().uncaughtException(cb, e);
591-
}
592-
catch (IllegalAccessException e) {
589+
catch (IllegalArgumentException | IllegalAccessException e) {
593590
Native.getCallbackExceptionHandler().uncaughtException(cb, e);
594591
}
595592
catch (InvocationTargetException e) {

src/com/sun/jna/Klass.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,7 @@ private Klass() {
4646
public static <T> T newInstance(Class<T> klass) {
4747
try {
4848
return klass.getDeclaredConstructor().newInstance();
49-
} catch (IllegalAccessException e) {
50-
String msg = "Can't create an instance of " + klass
51-
+ ", requires a public no-arg constructor: " + e;
52-
throw new IllegalArgumentException(msg, e);
53-
} catch (IllegalArgumentException e) {
54-
String msg = "Can't create an instance of " + klass
55-
+ ", requires a public no-arg constructor: " + e;
56-
throw new IllegalArgumentException(msg, e);
57-
} catch (InstantiationException e) {
58-
String msg = "Can't create an instance of " + klass
59-
+ ", requires a public no-arg constructor: " + e;
60-
throw new IllegalArgumentException(msg, e);
61-
} catch (NoSuchMethodException e) {
62-
String msg = "Can't create an instance of " + klass
63-
+ ", requires a public no-arg constructor: " + e;
64-
throw new IllegalArgumentException(msg, e);
65-
} catch (SecurityException e) {
49+
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException e) {
6650
String msg = "Can't create an instance of " + klass
6751
+ ", requires a public no-arg constructor: " + e;
6852
throw new IllegalArgumentException(msg, e);

src/com/sun/jna/Native.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,7 @@ private static Charset getCharset(String encoding) {
397397
try {
398398
charset = Charset.forName(encoding);
399399
}
400-
catch(IllegalCharsetNameException e) {
401-
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
402-
new Object[]{encoding, e.getMessage()});
403-
}
404-
catch(UnsupportedCharsetException e) {
400+
catch(IllegalCharsetNameException | UnsupportedCharsetException e) {
405401
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
406402
new Object[]{encoding, e.getMessage()});
407403
}

src/com/sun/jna/NativeLibrary.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,7 @@ private static void addSuppressedReflected(Throwable target, Throwable suppresse
352352
}
353353
try {
354354
addSuppressedMethod.invoke(target, suppressed);
355-
} catch (IllegalAccessException ex) {
356-
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
357-
} catch (IllegalArgumentException ex) {
358-
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
359-
} catch (InvocationTargetException ex) {
355+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
360356
throw new RuntimeException("Failed to call addSuppressedMethod", ex);
361357
}
362358
}

src/com/sun/jna/Structure.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -2325,9 +2325,7 @@ static void validate(Class<? extends Structure> cls) {
23252325
try {
23262326
cls.getConstructor();
23272327
return;
2328-
}catch(NoSuchMethodException e) {
2329-
}
2330-
catch(SecurityException e) {
2328+
}catch(NoSuchMethodException | SecurityException e) {
23312329
}
23322330
throw new IllegalArgumentException("No suitable constructor found for class: " + cls.getName());
23332331
}

src/com/sun/jna/VarArgsChecker.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ static VarArgsChecker create() {
8383
} else {
8484
return new NoVarArgsChecker();
8585
}
86-
} catch (NoSuchMethodException e) {
87-
return new NoVarArgsChecker();
88-
} catch (SecurityException e) {
86+
} catch (NoSuchMethodException | SecurityException e) {
8987
return new NoVarArgsChecker();
9088
}
9189
}

src/com/sun/jna/internal/ReflectionUtils.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ public static boolean isDefault(Method method) {
136136
}
137137
try {
138138
return (boolean) (Boolean) METHOD_IS_DEFAULT.invoke(method);
139-
} catch (IllegalAccessException ex) {
140-
throw new RuntimeException(ex);
141-
} catch (IllegalArgumentException ex) {
139+
} catch (IllegalAccessException | IllegalArgumentException ex) {
142140
throw new RuntimeException(ex);
143141
} catch (InvocationTargetException ex) {
144142
Throwable cause = ex.getCause();

test/com/sun/jna/StructureFieldOrderInspector.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ public static void checkMethodGetFieldOrder(final Class<? extends Structure> str
175175
final Structure structure;
176176
try {
177177
structure= structConstructor.newInstance();
178-
} catch (InstantiationException e) {
179-
throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
180-
} catch (IllegalAccessException e) {
178+
} catch (InstantiationException | IllegalAccessException e) {
181179
throw new RuntimeException("Could not instantiate Structure sub type: " + structureSubType.getName(), e);
182180
} catch (InvocationTargetException e) {
183181
// this is triggered by checks in Structure.getFields(), and static loadlibrary() failures

0 commit comments

Comments
 (0)