Skip to content

Commit cfb9496

Browse files
committed
address @kares's concern
1 parent 290037c commit cfb9496

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/java/arjdbc/jdbc/DriverWrapper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package arjdbc.jdbc;
2525

26+
import java.lang.reflect.InvocationTargetException;
2627
import java.sql.Connection;
2728
import java.sql.Driver;
2829
import 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
}

0 commit comments

Comments
 (0)