private static RaiseException initCause(final RaiseException ex, final Throwable cause) { ex.initCause(cause); return ex; }
private static RaiseException initCause(final RaiseException ex, final Throwable cause) { ex.initCause(cause); return ex; }
private static RaiseException mapGeneratedProxyException(final Ruby runtime, final InvocationTargetException e) { RaiseException ex = runtime.newTypeError("Exception instantiating generated interface impl:\n" + e.getTargetException()); ex.initCause(e); return ex; }
private static RaiseException mapInstantiationException(final Ruby runtime, final Throwable e) { Throwable cause = e; while ( cause.getCause() != null ) cause = cause.getCause(); final String MSG = "Constructor invocation failed: "; String msg = cause.getLocalizedMessage(); msg = msg == null ? ( MSG + e.getClass().getName() ) : ( MSG + msg ); RaiseException ex = runtime.newArgumentError(msg); ex.initCause(e); throw ex; }
private static RaiseException mapGeneratedProxyException(final Ruby runtime, final ReflectiveOperationException e) { RaiseException ex = runtime.newTypeError("Exception instantiating generated interface impl:\n" + e); ex.initCause(e); return ex; }
private static RaiseException mapGeneratedProxyException(final Ruby runtime, final InvocationTargetException e) { RaiseException ex = runtime.newTypeError("Exception instantiating generated interface impl:\n" + e.getTargetException()); ex.initCause(e); return ex; }
private static RaiseException mapGeneratedProxyException(final Ruby runtime, final ReflectiveOperationException e) { RaiseException ex = runtime.newTypeError("Exception instantiating generated interface impl:\n" + e); ex.initCause(e); return ex; }
private static RaiseException mapInstantiationException(final Ruby runtime, final Throwable e) { Throwable cause = e; while ( cause.getCause() != null ) cause = cause.getCause(); final String MSG = "Constructor invocation failed: "; String msg = cause.getLocalizedMessage(); msg = msg == null ? ( MSG + e.getClass().getName() ) : ( MSG + msg ); RaiseException ex = runtime.newArgumentError(msg); ex.initCause(e); throw ex; }
@SuppressWarnings("unchecked") private MapJavaProxy dupImpl(final String method) { final Map map = getMapObject(); try { Map newMap = map.getClass().newInstance(); newMap.putAll(map); MapJavaProxy proxy = new MapJavaProxy(getRuntime(), metaClass); proxy.setObject(newMap); return proxy; } catch (InstantiationException|IllegalAccessException ex) { final RaiseException e = getRuntime().newNotImplementedError("can't "+ method +" Map of type " + getObject().getClass().getName()); e.initCause(ex); throw e; } }
@SuppressWarnings("unchecked") private MapJavaProxy dupImpl(final String method) { final Map map = getMapObject(); try { Map newMap = map.getClass().newInstance(); newMap.putAll(map); MapJavaProxy proxy = new MapJavaProxy(getRuntime(), metaClass); proxy.setObject(newMap); return proxy; } catch (InstantiationException|IllegalAccessException ex) { final RaiseException e = getRuntime().newNotImplementedError("can't "+ method +" Map of type " + getObject().getClass().getName()); e.initCause(ex); throw e; } }
protected boolean tryLoadingLibraryOrScript(Ruby runtime, SearchState state) { // attempt to load the found library try { state.library.load(runtime, false); return true; } catch (MainExitException mee) { // allow MainExitException to propagate out for exec and friends throw mee; } catch (Throwable e) { if(isJarfileLibrary(state, state.searchFile)) { return true; } reraiseRaiseExceptions(e); if(runtime.getDebug().isTrue()) e.printStackTrace(runtime.getErr()); RaiseException re = newLoadErrorFromThrowable(runtime, state.searchFile, e); re.initCause(e); throw re; } }
protected boolean tryLoadingLibraryOrScript(Ruby runtime, SearchState state) { // attempt to load the found library try { state.library.load(runtime, false); return true; } catch (MainExitException mee) { // allow MainExitException to propagate out for exec and friends throw mee; } catch (Throwable e) { if(isJarfileLibrary(state, state.searchFile)) { return true; } reraiseRaiseExceptions(e); if(runtime.getDebug().isTrue()) e.printStackTrace(runtime.getErr()); RaiseException re = newLoadErrorFromThrowable(runtime, state.searchFile, e); re.initCause(e); throw re; } }
@JRubyMethod(required = 1, optional = 1) public RubyObject new_instance(IRubyObject[] args, Block block) { final Ruby runtime = getRuntime(); final int last = Arity.checkArgumentCount(runtime, args, 1, 2) - 1; final RubyProc proc; // Is there a supplied proc arg or do we assume a block was supplied if (args[last] instanceof RubyProc) { proc = (RubyProc) args[last]; } else { proc = runtime.newProc(Block.Type.PROC, block); } final Object[] convertedArgs = convertArguments((RubyArray) args[0]); JavaProxyInvocationHandler handler = new ProcInvocationHandler(runtime, proc); try { return JavaObject.wrap(runtime, newInstance(convertedArgs, handler)); } catch (Exception e) { RaiseException ex = runtime.newArgumentError("Constructor invocation failed: " + e.getMessage()); ex.initCause(e); throw ex; } }
@JRubyMethod(required = 1, optional = 1) public RubyObject new_instance(IRubyObject[] args, Block block) { final Ruby runtime = getRuntime(); final int last = Arity.checkArgumentCount(runtime, args, 1, 2) - 1; final RubyProc proc; // Is there a supplied proc arg or do we assume a block was supplied if (args[last] instanceof RubyProc) { proc = (RubyProc) args[last]; } else { proc = runtime.newProc(Block.Type.PROC, block); } final Object[] convertedArgs = convertArguments((RubyArray) args[0]); JavaProxyInvocationHandler handler = new ProcInvocationHandler(runtime, proc); try { return JavaObject.wrap(runtime, newInstance(convertedArgs, handler)); } catch (Exception e) { RaiseException ex = runtime.newArgumentError("Constructor invocation failed: " + e.getMessage()); ex.initCause(e); throw ex; } }
@JRubyMethod(meta = true) public static RubyObject get(IRubyObject recv, IRubyObject obj) { if (!(obj instanceof JavaClass)) { throw recv.getRuntime().newTypeError(obj, recv.getRuntime().getJavaSupport().getJavaClassClass()); } JavaClass type = (JavaClass)obj; try { return getProxyClass(recv.getRuntime(), (Class) type.getValue(), new Class[0]); } catch (Error e) { RaiseException ex = recv.getRuntime().newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } catch (InvocationTargetException e) { RaiseException ex = recv.getRuntime().newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } }
@JRubyMethod(meta = true) public static RubyObject get(IRubyObject recv, IRubyObject obj) { if (!(obj instanceof JavaClass)) { throw recv.getRuntime().newTypeError(obj, recv.getRuntime().getJavaSupport().getJavaClassClass()); } JavaClass type = (JavaClass)obj; try { return getProxyClass(recv.getRuntime(), (Class) type.getValue(), new Class[0]); } catch (Error e) { RaiseException ex = recv.getRuntime().newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } catch (InvocationTargetException e) { RaiseException ex = recv.getRuntime().newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } }
@JRubyMethod(meta = true) public static RubyObject get(IRubyObject self, IRubyObject obj) { final Ruby runtime = self.getRuntime(); if ( ! ( obj instanceof JavaClass ) ) { throw runtime.newTypeError(obj, runtime.getJavaSupport().getJavaClassClass()); } final JavaClass type = (JavaClass) obj; try { return getProxyClass(runtime, type.javaClass(), EMPTY_CLASS_ARRAY); } catch (InvocationTargetException|Error e) { RaiseException ex = runtime.newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } }
@JRubyMethod(meta = true) public static RubyObject get(IRubyObject self, IRubyObject obj) { final Ruby runtime = self.getRuntime(); if ( ! ( obj instanceof JavaClass ) ) { throw runtime.newTypeError(obj, runtime.getJavaSupport().getJavaClassClass()); } final JavaClass type = (JavaClass) obj; try { return getProxyClass(runtime, type.javaClass(), EMPTY_CLASS_ARRAY); } catch (InvocationTargetException|Error e) { RaiseException ex = runtime.newArgumentError("unable to create proxy class for " + type.getValue()); ex.initCause(e); throw ex; } }
public static void createDigestSHA2(Ruby runtime) { runtime.getLoadService().require("digest"); try { createMessageDigest("SHA-256"); } catch (NoSuchAlgorithmException e) { RaiseException ex = runtime.newLoadError("SHA2 not supported"); ex.initCause(e); throw ex; } final RubyModule Digest = runtime.getModule("Digest"); final RubyClass Base = Digest.getClass("Base"); RubyClass SHA256 = Digest.defineClassUnder("SHA256", Base, Base.getAllocator()); SHA256.setInternalVariable("metadata", new Metadata("SHA-256", 64)); RubyClass SHA384 = Digest.defineClassUnder("SHA384", Base, Base.getAllocator()); SHA384.setInternalVariable("metadata", new Metadata("SHA-384", 128)); RubyClass SHA512 = Digest.defineClassUnder("SHA512", Base, Base.getAllocator()); SHA512.setInternalVariable("metadata", new Metadata("SHA-512", 128)); }
public static void createDigestSHA2(Ruby runtime) { runtime.getLoadService().require("digest"); try { createMessageDigest("SHA-256"); } catch (NoSuchAlgorithmException e) { RaiseException ex = runtime.newLoadError("SHA2 not supported"); ex.initCause(e); throw ex; } final RubyModule Digest = runtime.getModule("Digest"); final RubyClass Base = Digest.getClass("Base"); RubyClass SHA256 = Digest.defineClassUnder("SHA256", Base, Base.getAllocator()); SHA256.setInternalVariable("metadata", new Metadata("SHA-256", 64)); RubyClass SHA384 = Digest.defineClassUnder("SHA384", Base, Base.getAllocator()); SHA384.setInternalVariable("metadata", new Metadata("SHA-384", 128)); RubyClass SHA512 = Digest.defineClassUnder("SHA512", Base, Base.getAllocator()); SHA512.setInternalVariable("metadata", new Metadata("SHA-512", 128)); }