TINKERPOP-1595 Refactored reflective lookups for clone() Rather than iterate all methods to find clone() just call getMethod() and call that if found. Nothing seems to be exercising this bit of code in our test suite. I forced it by adding clone() temporarily to RangeBiOperator and it worked without issue. Not sure how else to test this.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1d149c6d Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1d149c6d Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1d149c6d Branch: refs/heads/TINKERPOP-1595 Commit: 1d149c6d56421bacecdd53ab0c223f386bc999db Parents: 91f078a Author: Stephen Mallette <[email protected]> Authored: Tue Apr 24 08:03:28 2018 -0400 Committer: Stephen Mallette <[email protected]> Committed: Fri Apr 27 10:32:44 2018 -0400 ---------------------------------------------------------------------- .../gremlin/process/computer/MemoryComputeKey.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1d149c6d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/MemoryComputeKey.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/MemoryComputeKey.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/MemoryComputeKey.java index 70adf3d..a9b1532 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/MemoryComputeKey.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/MemoryComputeKey.java @@ -79,14 +79,17 @@ public final class MemoryComputeKey<A> implements Serializable, Cloneable { public MemoryComputeKey<A> clone() { try { final MemoryComputeKey<A> clone = (MemoryComputeKey<A>) super.clone(); - for (final Method method : this.reducer.getClass().getMethods()) { - if (method.getName().equals("clone") && 0 == method.getParameterCount()) { - clone.reducer = (BinaryOperator<A>) method.invoke(this.reducer); - break; - } + + try { + final Method cloneMethod = this.reducer.getClass().getMethod("clone"); + if (cloneMethod != null) + clone.reducer = (BinaryOperator<A>) cloneMethod.invoke(this.reducer); + } catch(Exception ignored) { + } + return clone; - } catch (final IllegalAccessException | InvocationTargetException | CloneNotSupportedException e) { + } catch (final CloneNotSupportedException e) { throw new IllegalStateException(e.getMessage(), e); } }
