File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2323 */
2424package arjdbc .jdbc ;
2525
26+ import java .lang .reflect .InvocationTargetException ;
2627import java .sql .Connection ;
2728import java .sql .Driver ;
2829import java .sql .SQLException ;
@@ -61,7 +62,17 @@ public Driver getDriverInstance() {
6162 private Driver allocateDriver (final Class <? extends Driver > driverClass ) {
6263 try {
6364 return driverClass .getDeclaredConstructor ().newInstance ();
64- } catch (ReflectiveOperationException e ) {
65+ } catch (InvocationTargetException e ) {
66+ // emulate Class.newInstance() behavior: unwrap and rethrow the real cause
67+ Throwable cause = e .getCause ();
68+ if (cause instanceof RuntimeException ) {
69+ throw (RuntimeException ) cause ;
70+ } else if (cause instanceof Error ) {
71+ throw (Error ) cause ;
72+ } else {
73+ throw new RuntimeException ("Constructor threw checked exception" , cause );
74+ }
75+ } catch (IllegalAccessException | InstantiationException | NoSuchMethodException e ) {
6576 throw new IllegalStateException ("Failed to instantiate driver: " + driverClass .getName (), e );
6677 }
6778 }
You can’t perform that action at this time.
0 commit comments