From 029a7795e7d04e99a5630105bfa3da567e6c3e27 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 11 Apr 2024 12:01:55 +0200 Subject: [PATCH] [refactor] make sure ASN1Error has native cause --- src/main/java/org/jruby/ext/openssl/ASN1.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index fbe08bb9..a4c52f47 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -1127,12 +1127,11 @@ public static IRubyObject decode(final ThreadContext context, return decodeImpl(context, (RubyModule) self, obj); } catch (IOException e) { - //throw context.runtime.newIOErrorFromException(e); - throw newASN1Error(context.runtime, e.getMessage()); + throw newASN1Error(context.runtime, e); } catch (IllegalArgumentException e) { debugStackTrace(context.runtime, e); - throw context.runtime.newArgumentError(e.getMessage()); + throw (RaiseException) context.runtime.newArgumentError(e.getMessage()).initCause(e); } catch (RuntimeException e) { @@ -1212,8 +1211,7 @@ public static IRubyObject decode_all(final ThreadContext context, arr.append( decodeImpl(context, ASN1, in) ); } catch (IOException e) { - //throw context.runtime.newIOErrorFromException(e); - throw newASN1Error(context.runtime, e.getMessage()); + throw newASN1Error(context.runtime, e); } catch (IllegalArgumentException e) { debugStackTrace(context.runtime, e); @@ -1233,6 +1231,10 @@ public static RaiseException newASN1Error(Ruby runtime, String message) { return Utils.newError(runtime, _ASN1(runtime).getClass("ASN1Error"), message, false); } + static RaiseException newASN1Error(Ruby runtime, Throwable ex) { + return (RaiseException) newASN1Error(runtime, ex.getMessage()).initCause(ex); + } + static RubyModule _ASN1(final Ruby runtime) { return (RubyModule) runtime.getModule("OpenSSL").getConstant("ASN1"); }