Skip to content

Commit e6691d3

Browse files
authored
Merge pull request #990 from dr-itz/50-dev
WIP: Remove use of deprecated (in 9.2) Exceptions API
2 parents df99548 + a01aaee commit e6691d3

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

src/java/arjdbc/ArJdbcModule.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Map;
3030
import java.util.WeakHashMap;
3131

32-
import org.jruby.NativeException;
3332
import org.jruby.Ruby;
3433
import org.jruby.RubyArray;
3534
import org.jruby.RubyClass;
@@ -148,13 +147,7 @@ public static IRubyObject load_java_part(final ThreadContext context,
148147
}
149148
}
150149
catch (ClassNotFoundException e) { /* ignored */ }
151-
catch (NoSuchMethodException e) {
152-
throw newNativeException(runtime, e);
153-
}
154-
catch (IllegalAccessException e) {
155-
throw newNativeException(runtime, e);
156-
}
157-
catch (InvocationTargetException e) {
150+
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
158151
throw newNativeException(runtime, e);
159152
}
160153

@@ -263,18 +256,15 @@ private static Object invokeStatic(final Ruby runtime,
263256
try {
264257
return klass.getMethod(name, argType).invoke(null, arg);
265258
}
266-
catch (IllegalAccessException e) {
267-
throw newNativeException(runtime, e);
268-
}
269-
catch (InvocationTargetException e) {
259+
catch (IllegalAccessException | InvocationTargetException e) {
270260
throw newNativeException(runtime, e);
271261
}
272262
}
273263

274264
private static RaiseException newNativeException(final Ruby runtime, final Throwable cause) {
275-
RubyClass nativeClass = runtime.getClass(NativeException.CLASS_NAME);
276-
NativeException nativeException = new NativeException(runtime, nativeClass, cause);
277-
return new RaiseException(cause, nativeException);
265+
final RaiseException error = runtime.newRuntimeError(cause.toString());
266+
error.initCause(cause);
267+
return error;
278268
}
279269

280270
@JRubyMethod(meta = true)

src/java/arjdbc/derby/DerbyRubyJdbcConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ protected DriverWrapper newDriverWrapper(final ThreadContext context, final Stri
8383
final int minor = jdbcDriver.getMinorVersion();
8484
if ( major < 10 || ( major == 10 && minor < 5 ) ) {
8585
final RubyClass errorClass = getConnectionNotEstablished(context.runtime);
86-
throw new RaiseException(context.runtime, errorClass,
87-
"adapter requires Derby >= 10.5 got: " + major + "." + minor + "", false);
86+
throw context.runtime.newRaiseException(errorClass,
87+
"adapter requires Derby >= 10.5 got: " + major + "." + minor + "");
8888
}
8989
if ( major == 10 && minor < 8 ) { // 10.8 ~ supports JDBC 4.1
9090
// config[:connection_alive_sql] ||= 'SELECT 1 FROM SYS.SYSSCHEMAS FETCH FIRST 1 ROWS ONLY'

src/java/arjdbc/jdbc/RubyJdbcConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ private ConnectionFactory setDriverFactory(final ThreadContext context) {
18071807
if ( url.isNil() || ( driver.isNil() && driver_instance.isNil() ) ) {
18081808
final Ruby runtime = context.runtime;
18091809
final RubyClass errorClass = getConnectionNotEstablished( runtime );
1810-
throw new RaiseException(runtime, errorClass, "adapter requires :driver class and jdbc :url", false);
1810+
throw runtime.newRaiseException(errorClass, "adapter requires :driver class and jdbc :url");
18111811
}
18121812

18131813
final String jdbcURL = buildURL(context, url);
@@ -3004,7 +3004,7 @@ private Connection getConnectionInternal(final boolean required) throws SQLExcep
30043004
private void handleNotConnected() {
30053005
final Ruby runtime = getRuntime();
30063006
final RubyClass errorClass = getConnectionNotEstablished( runtime );
3007-
throw new RaiseException(runtime, errorClass, "no connection available", false);
3007+
throw runtime.newRaiseException(errorClass, "no connection available");
30083008
}
30093009

30103010
/**
@@ -3541,7 +3541,7 @@ protected RaiseException wrapException(final ThreadContext context, final Throwa
35413541
return (RaiseException) exception;
35423542
}
35433543
if ( exception instanceof RuntimeException ) {
3544-
return RaiseException.createNativeRaiseException(runtime, exception);
3544+
return wrapException(context, context.runtime.getRuntimeError(), exception);
35453545
}
35463546
// NOTE: compat - maybe makes sense or maybe not (e.g. IOException) :
35473547
return wrapException(context, getJDBCError(runtime), exception);
@@ -3554,7 +3554,7 @@ public static RaiseException wrapException(final ThreadContext context,
35543554

35553555
public static RaiseException wrapException(final ThreadContext context,
35563556
final RubyClass errorClass, final Throwable exception, final String message) {
3557-
final RaiseException error = new RaiseException(context.runtime, errorClass, message, true);
3557+
final RaiseException error = context.runtime.newRaiseException(errorClass, message);
35583558
error.initCause(exception);
35593559
return error;
35603560
}

src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ protected DriverWrapper newDriverWrapper(final ThreadContext context, final Stri
107107
final int minor = jdbcDriver.getMinorVersion();
108108
if ( major < 5 ) {
109109
final RubyClass errorClass = getConnectionNotEstablished(context.runtime);
110-
throw new RaiseException(context.runtime, errorClass,
111-
"MySQL adapter requires driver >= 5.0 got: " + major + "." + minor + "", false);
110+
throw context.runtime.newRaiseException(errorClass,
111+
"MySQL adapter requires driver >= 5.0 got: " + major + "." + minor + "");
112112
}
113113
if ( major == 5 && minor < 1 ) { // need 5.1 for JDBC 4.0
114114
// lightweight validation query: "/* ping */ SELECT 1"

0 commit comments

Comments
 (0)