Skip to content

Commit 290037c

Browse files
committed
remove anti-pattern with security issues
1 parent 725da07 commit 290037c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/java/arjdbc/jdbc/DriverWrapper.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class DriverWrapper {
4545
private final Properties properties;
4646

4747
DriverWrapper(final Ruby runtime, final String name, final Properties properties)
48-
throws ClassCastException, InstantiationException, IllegalAccessException {
48+
throws ClassCastException {
4949
this.driver = allocateDriver( loadDriver(runtime, name) );
5050
this.properties = properties == null ? new Properties() : properties;
5151
}
@@ -58,9 +58,12 @@ public Driver getDriverInstance() {
5858
return driver;
5959
}
6060

61-
private Driver allocateDriver(final Class<? extends Driver> driverClass)
62-
throws InstantiationException, IllegalAccessException {
63-
return driverClass.newInstance();
61+
private Driver allocateDriver(final Class<? extends Driver> driverClass) {
62+
try {
63+
return driverClass.getDeclaredConstructor().newInstance();
64+
} catch (ReflectiveOperationException e) {
65+
throw new IllegalStateException("Failed to instantiate driver: " + driverClass.getName(), e);
66+
}
6467
}
6568

6669
protected static Class<? extends Driver> loadDriver(final Ruby runtime, final String name)

src/java/arjdbc/jdbc/RubyJdbcConnection.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,10 +1818,6 @@ protected DriverWrapper newDriverWrapper(final ThreadContext context, final Stri
18181818
catch (ClassCastException e) {
18191819
throw wrapException(context, context.runtime.getNameError(), e);
18201820
}
1821-
catch (IllegalAccessException e) { throw wrapException(context, e); }
1822-
catch (InstantiationException e) {
1823-
throw wrapException(context, e.getCause() != null ? e.getCause() : e);
1824-
}
18251821
catch (SecurityException e) {
18261822
throw wrapException(context, context.runtime.getSecurityError(), e);
18271823
}

0 commit comments

Comments
 (0)