From 00fcacee8fc42186331e2721286a13f929cabf5f Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Wed, 28 Feb 2018 14:47:08 +0100 Subject: [PATCH] No methodHandle#invokeWithArguments for procedures --- .../proc/ReflectiveProcedureCompiler.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ReflectiveProcedureCompiler.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ReflectiveProcedureCompiler.java index 00be8514a8e0c..3eb4c78553de2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ReflectiveProcedureCompiler.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/proc/ReflectiveProcedureCompiler.java @@ -240,8 +240,6 @@ private CallableProcedure compileProcedure( Class procDefinition, MethodHandl Optional warning, boolean fullAccess, QualifiedName procName ) throws ProcedureException, IllegalAccessException { - MethodHandle procedureMethod = lookup.unreflect( method ); - List inputSignature = inputSignatureDeterminer.signatureFor( method ); OutputMapper outputMapper = outputMappers.mapper( method ); @@ -284,7 +282,7 @@ private CallableProcedure compileProcedure( Class procDefinition, MethodHandl ProcedureSignature signature = new ProcedureSignature( procName, inputSignature, outputMapper.signature(), mode, deprecated, config.rolesFor( procName.toString() ), description, warning ); - return new ReflectiveProcedure( signature, constructor, procedureMethod, outputMapper, setters ); + return new ReflectiveProcedure( signature, constructor, method, outputMapper, setters ); } private Optional describeAndLogLoadFailure( QualifiedName name ) @@ -555,10 +553,10 @@ private static class ReflectiveProcedure extends ReflectiveBase implements Calla private final ProcedureSignature signature; private final OutputMapper outputMapper; private final MethodHandle constructor; - private final MethodHandle procedureMethod; + private final Method procedureMethod; ReflectiveProcedure( ProcedureSignature signature, MethodHandle constructor, - MethodHandle procedureMethod, OutputMapper outputMapper, + Method procedureMethod, OutputMapper outputMapper, List fieldSetters ) { super( fieldSetters ); @@ -596,9 +594,7 @@ public RawIterator apply( Context ctx, Object[] inp inject( ctx, cls ); // Call the method - Object[] args = args( numberOfDeclaredArguments, cls, input ); - - Object rs = procedureMethod.invokeWithArguments( args ); + Object rs = procedureMethod.invoke( cls, input ); // This also handles VOID if ( rs == null ) @@ -702,10 +698,18 @@ private ProcedureException closeAndCreateProcedureException( Throwable t ) private ProcedureException newProcedureException( Throwable throwable ) { - return throwable instanceof Status.HasStatus ? - new ProcedureException( ((Status.HasStatus) throwable).status(), throwable, throwable.getMessage() ) : - new ProcedureException( Status.Procedure.ProcedureCallFailed, throwable, - "Failed to invoke procedure `%s`: %s", signature.name(), "Caused by: " + throwable ); + if (throwable instanceof Status.HasStatus ) + { + return new ProcedureException( ((Status.HasStatus) throwable).status(), throwable, throwable.getMessage() ); + } + else + { + Throwable cause = ExceptionUtils.getRootCause( throwable ); + return new ProcedureException( Status.Procedure.ProcedureCallFailed, throwable, + "Failed to invoke procedure `%s`: %s", signature.name(), + "Caused by: " + (cause != null ? cause : throwable) ); + } + } }