Skip to content

Commit 6298283

Browse files
committed
use multi-catch to simplify code
1 parent 1da9739 commit 6298283

File tree

25 files changed

+107
-301
lines changed

25 files changed

+107
-301
lines changed

jme3-bullet/src/common/java/com/jme3/bullet/BulletAppState.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2020 jMonkeyEngine
2+
* Copyright (c) 2009-2021 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -192,10 +192,7 @@ public Boolean call() throws Exception {
192192
};
193193
try {
194194
return executor.submit(call).get();
195-
} catch (InterruptedException ex) {
196-
Logger.getLogger(BulletAppState.class.getName()).log(Level.SEVERE, null, ex);
197-
return false;
198-
} catch (ExecutionException ex) {
195+
} catch (InterruptedException | ExecutionException ex) {
199196
Logger.getLogger(BulletAppState.class.getName()).log(Level.SEVERE, null, ex);
200197
return false;
201198
}
@@ -388,9 +385,7 @@ public void postRender() {
388385
try {
389386
physicsFuture.get();
390387
physicsFuture = null;
391-
} catch (InterruptedException ex) {
392-
Logger.getLogger(BulletAppState.class.getName()).log(Level.SEVERE, null, ex);
393-
} catch (ExecutionException ex) {
388+
} catch (InterruptedException | ExecutionException ex) {
394389
Logger.getLogger(BulletAppState.class.getName()).log(Level.SEVERE, null, ex);
395390
}
396391
}

jme3-core/src/main/java/com/jme3/anim/tween/Tweens.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2020 jMonkeyEngine
2+
* Copyright (c) 2015-2021 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -469,9 +469,7 @@ private static Method findMethod(Class type, String name, Object... args) {
469469
protected void doInterpolate(double t) {
470470
try {
471471
method.invoke(target, args);
472-
} catch (IllegalAccessException e) {
473-
throw new RuntimeException("Error running method:" + method + " for object:" + target, e);
474-
} catch (InvocationTargetException e) {
472+
} catch (IllegalAccessException | InvocationTargetException e) {
475473
throw new RuntimeException("Error running method:" + method + " for object:" + target, e);
476474
}
477475
}
@@ -600,9 +598,7 @@ protected void doInterpolate(double t) {
600598
args[tIndex] = t;
601599
}
602600
method.invoke(target, args);
603-
} catch (IllegalAccessException e) {
604-
throw new RuntimeException("Error running method:" + method + " for object:" + target, e);
605-
} catch (InvocationTargetException e) {
601+
} catch (IllegalAccessException | InvocationTargetException e) {
606602
throw new RuntimeException("Error running method:" + method + " for object:" + target, e);
607603
}
608604
}

jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ public void registerLoader(String clsName, String ... extensions){
148148
Class<? extends AssetLoader> clazz = null;
149149
try{
150150
clazz = (Class<? extends AssetLoader>) Class.forName(clsName);
151-
}catch (ClassNotFoundException ex){
152-
logger.log(Level.WARNING, "Failed to find loader: "+clsName, ex);
153-
}catch (NoClassDefFoundError ex){
151+
} catch (ClassNotFoundException | NoClassDefFoundError ex) {
154152
logger.log(Level.WARNING, "Failed to find loader: "+clsName, ex);
155153
}
156154
if (clazz != null){

jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ public static Savable fromName(String className, List<ClassLoader> loaders) thro
212212
}
213213
try {
214214
return (Savable) loadedClass.newInstance();
215-
} catch (InstantiationException e) {
216-
} catch (IllegalAccessException e) {
215+
} catch (InstantiationException | IllegalAccessException e) {
217216
}
218217
}
219218
}

jme3-core/src/main/java/com/jme3/renderer/opengl/GLTracer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ private static IntMap<String> generateConstantMap(Class<?> ... classes) {
152152
int val = field.getInt(null);
153153
String name = field.getName();
154154
constMap.put(val, name);
155-
} catch (IllegalArgumentException ex) {
156-
} catch (IllegalAccessException ex) {
155+
} catch (IllegalArgumentException
156+
| IllegalAccessException ex) {
157157
}
158158
}
159159
}

jme3-core/src/main/java/com/jme3/system/JmeSystem.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2019 jMonkeyEngine
2+
* Copyright (c) 2009-2021 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -212,9 +212,7 @@ private static void checkDelegate() {
212212
}
213213
}
214214
}
215-
} catch (InstantiationException ex) {
216-
Logger.getLogger(JmeSystem.class.getName()).log(Level.SEVERE, "Failed to create JmeSystem delegate:\n{0}", ex);
217-
} catch (IllegalAccessException ex) {
215+
} catch (InstantiationException | IllegalAccessException ex) {
218216
Logger.getLogger(JmeSystem.class.getName()).log(Level.SEVERE, "Failed to create JmeSystem delegate:\n{0}", ex);
219217
}
220218
}

jme3-core/src/main/java/com/jme3/util/MaterialDebugAppState.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ public void reload() {
349349
}
350350
}
351351
}
352-
} catch (IllegalArgumentException ex) {
353-
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
354-
} catch (IllegalAccessException ex) {
352+
} catch (IllegalArgumentException | IllegalAccessException ex) {
355353
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
356354
}
357355

@@ -388,13 +386,10 @@ public void init() {
388386
file = new File(url.getFile());
389387
fileLastM = file.lastModified();
390388

391-
} catch (NoSuchFieldException ex) {
392-
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
393-
} catch (SecurityException ex) {
394-
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
395-
} catch (IllegalArgumentException ex) {
396-
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
397-
} catch (IllegalAccessException ex) {
389+
} catch (NoSuchFieldException
390+
| SecurityException
391+
| IllegalArgumentException
392+
| IllegalAccessException ex) {
398393
Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex);
399394
}
400395
}

jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2020 jMonkeyEngine
2+
* Copyright (c) 2009-2021 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -64,8 +64,7 @@ public final class ReflectionAllocator implements BufferAllocator {
6464
Class<?> clazz = bb.getClass();
6565
try {
6666
freeMethod = clazz.getMethod("free");
67-
} catch (NoSuchMethodException ex) {
68-
} catch (SecurityException ex) {
67+
} catch (NoSuchMethodException | SecurityException ex) {
6968
}
7069
}
7170

@@ -74,12 +73,10 @@ private static Method loadMethod(String className, String methodName) {
7473
Method method = Class.forName(className).getMethod(methodName);
7574
method.setAccessible(true);// according to the Java documentation, by default, a reflected object is not accessible
7675
return method;
77-
} catch (NoSuchMethodException ex) {
78-
return null; // the method was not found
79-
} catch (SecurityException ex) {
80-
return null; // setAccessible not allowed by security policy
81-
} catch (ClassNotFoundException ex) {
82-
return null; // the direct buffer implementation was not found
76+
} catch (NoSuchMethodException // the method was not found
77+
| SecurityException // setAccessible not allowed by security policy
78+
| ClassNotFoundException ex) { // the direct buffer implementation was not found
79+
return null;
8380
} catch (Throwable t) {
8481
if (t.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
8582
return null;// the class is in an unexported module
@@ -162,13 +159,10 @@ public void destroyDirectBuffer(Buffer toBeDestroyed) {
162159
}
163160
}
164161
}
165-
} catch (IllegalAccessException ex) {
166-
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
167-
} catch (IllegalArgumentException ex) {
168-
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
169-
} catch (InvocationTargetException ex) {
170-
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
171-
} catch (SecurityException ex) {
162+
} catch (IllegalAccessException
163+
| IllegalArgumentException
164+
| InvocationTargetException
165+
| SecurityException ex) {
172166
Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
173167
}
174168
}

jme3-core/src/test/java/com/jme3/scene/MPOTestUtils.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,10 @@ private static int getRefreshFlags(Spatial scene) {
102102
Field refreshFlagsField = Spatial.class.getDeclaredField("refreshFlags");
103103
refreshFlagsField.setAccessible(true);
104104
return (Integer) refreshFlagsField.get(scene);
105-
} catch (NoSuchFieldException ex) {
106-
throw new AssertionError(ex);
107-
} catch (SecurityException ex) {
108-
throw new AssertionError(ex);
109-
} catch (IllegalArgumentException ex) {
110-
throw new AssertionError(ex);
111-
} catch (IllegalAccessException ex) {
105+
} catch (NoSuchFieldException
106+
| SecurityException
107+
| IllegalArgumentException
108+
| IllegalAccessException ex) {
112109
throw new AssertionError(ex);
113110
}
114111
}

jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ private Image convertImageToAwt(Image source) {
359359
Image newImage = new Image(format, source.getWidth(), source.getHeight(), BufferUtils.createByteBuffer(source.getWidth() * source.getHeight() * 4), null, ColorSpace.Linear);
360360
clazz.getMethod("convert", Image.class, Image.class).invoke(clazz.newInstance(), source, newImage);
361361
return newImage;
362-
} catch (InstantiationException ex) {
363-
} catch (IllegalAccessException ex) {
364-
} catch (IllegalArgumentException ex) {
365-
} catch (InvocationTargetException ex) {
366-
} catch (NoSuchMethodException ex) {
367-
} catch (SecurityException ex) {
368-
} catch (ClassNotFoundException ex) {
362+
} catch (InstantiationException
363+
| IllegalAccessException
364+
| IllegalArgumentException
365+
| InvocationTargetException
366+
| NoSuchMethodException
367+
| SecurityException
368+
| ClassNotFoundException ex) {
369369
}
370370
return null;
371371
}

0 commit comments

Comments
 (0)