java.lang.invoke.WrongMethodTypeException Java Examples
The following examples show how to use
java.lang.invoke.WrongMethodTypeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeCalls.java From es6draft with MIT License | 6 votes |
private static MethodHandle forSpreadCall(MethodHandle mh, MethodType type) { int expectedParameters = mh.type().parameterCount(); int actualParameters = type.parameterCount(); if (!mh.isVarargsCollector() || !mh.type().parameterType(expectedParameters - 1).equals(Object[].class)) { throw new WrongMethodTypeException("Not Object[] var-args collector"); } if (expectedParameters > actualParameters) { throw new WrongMethodTypeException("Too few arguments"); } if (expectedParameters < actualParameters) { int fixedCount = actualParameters - expectedParameters; int firstFixed = expectedParameters - 1; List<Class<?>> fixed = type.parameterList().subList(firstFixed, firstFixed + fixedCount); mh = MethodHandles.collectArguments(mh, firstFixed, combineArraysMH); mh = MethodHandles.collectArguments(mh, firstFixed, toObjectArray(fixed)); } return mh.asType(type); }
Example #2
Source File: TransactionMethod.java From exonum-java-binding with Apache License 2.0 | 6 votes |
void invoke(Service targetService, byte[] arguments, ExecutionContext context) { Object argumentsObject = serializeArguments(arguments); try { methodHandle.invoke(targetService, argumentsObject, context); } catch (WrongMethodTypeException | ClassCastException invocationException) { // Invocation-specific exceptions are thrown as is — they are not thrown // from the _transaction method_, but from framework code (see mh#invoke spec). throw invocationException; } catch (ExecutionException serviceException) { // 'Service-defined' transaction exceptions throw serviceException; } catch (Throwable unexpectedServiceException) { // Any other _transaction_ exceptions throw new UnexpectedExecutionException(unexpectedServiceException); } }
Example #3
Source File: ModuleOverrideHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
/** * Invokes the override implementation. * * @param args passed arguments * @return the return value from the override call. * @throws Throwable any occurred exception thrown by the override implementation or by the Java Method Handler. */ Object invoke(Object[] args) throws Throwable { int idxContextParamRing = baseMethod.getIdxContextParamRing(); int idxContextParamSuper = baseMethod.getIdxContextParamSuper(); Object passedArgs[] = args; int countExtra = 1; if (idxContextParamRing >= 0) countExtra++; if (idxContextParamSuper >= 0) countExtra++; // Add extra arguments like this pointer a.s.o. passedArgs = new Object[args.length + countExtra]; int i = 0; int j = 0; while (i < passedArgs.length) { if (i == 0) { passedArgs[i] = object; } else if (i == idxContextParamRing + 1) { passedArgs[i] = spellRingWithOverride; } else if (i == idxContextParamSuper + 1) { passedArgs[i] = new ModuleOverrideSuper(prev); } else { passedArgs[i] = args[j]; j++; } i++; } try { return baseMethod.getMethodHandle().invokeWithArguments(passedArgs); } catch (WrongMethodTypeException | ClassCastException e) { // NOTE: If this happens, then correctness of checks like "areMethodsCompatible()" a.s.o. need to be debugged. throw new IllegalStateException("Couldn't invoke call. See cause.", e); } }
Example #4
Source File: ExplicitCastArgumentsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #5
Source File: BigArityTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); MethodHandle mh_VA_h = mh.asSpreader(0, cls, arity-1); assert(mh_VA.type().parameterType(0) == cls); assert(mh_VA_h.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA, mh_VA_h); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); MethodHandle mh_VA2_h = mh_CA.asSpreader(0, cls, arity-1); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2, mh_VA2_h); } }
Example #6
Source File: ExplicitCastArgumentsTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #7
Source File: BigArityTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #8
Source File: ExplicitCastArgumentsTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #9
Source File: BigArityTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #10
Source File: BigArityTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #11
Source File: BigArityTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #12
Source File: BigArityTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #13
Source File: ExplicitCastArgumentsTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #14
Source File: BigArityTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #15
Source File: BigArityTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #16
Source File: BigArityTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #17
Source File: MethodBuilder.java From proxy2 with Apache License 2.0 | 5 votes |
/** * Create a method handle that will apply all transformations specified by the current method builder * and then call the {@code method} method. * This method uses a cache if the method is a virtual method (either on class or interface) * * @param lookup the lookup object used to find the @code method} * @param method the method called at the end of the transformation. * @return a new method handle constructed by applying all transformations on the target method. * @throws NoSuchMethodException throws is a method is not visible. * @throws NoSuchFieldException throws if a field is not visible. * @throws IllegalAccessException throws if a type or a member of a type is not visible. */ public MethodHandle unreflect(Lookup lookup, Method method) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException { MethodHandle target = lookup.unreflect(method); MethodType targetType = target.type(); if (!targetType.equals(sig)) { throw new WrongMethodTypeException("target type " + targetType + " is not equals to current type " + sig); } int modifiers = method.getModifiers(); if (!Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) { // can be virtual target = new InliningCacheCallSite(target).dynamicInvoker(); } return call(target); }
Example #18
Source File: MethodHandlesTest.java From tutorials with MIT License | 5 votes |
@Test(expected = WrongMethodTypeException.class) public void givenSumMethodHandleAndIncompatibleArguments_whenInvokingExact_thenException() throws Throwable { MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodType mt = MethodType.methodType(int.class, int.class, int.class); MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt); sumMH.invokeExact(Integer.valueOf(1), 11); }
Example #19
Source File: ExplicitCastArgumentsTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #20
Source File: ExplicitCastArgumentsTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #21
Source File: ApimlInstanceRegistry.java From api-layer with Eclipse Public License 2.0 | 5 votes |
protected int resolveInstanceLeaseDurationRewritten(final InstanceInfo info) { try { return (int) handlerResolveInstanceLeaseDurationMethod.invokeWithArguments(this, info); } catch (ClassCastException | WrongMethodTypeException e) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, e); } catch (RuntimeException re) { throw re; } catch (Throwable t) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, t); } }
Example #22
Source File: BigArityTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #23
Source File: ExplicitCastArgumentsTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #24
Source File: BigArityTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #25
Source File: BigArityTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #26
Source File: ExplicitCastArgumentsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) { try { MethodHandles.explicitCastArguments(mh, mt); throw new AssertionError("Expected WrongMethodTypeException is not thrown"); } catch (WrongMethodTypeException wmte) { if (VERBOSE) { System.out.printf("Expected exception %s: %s\n", wmte.getClass(), wmte.getMessage()); } } }
Example #27
Source File: ApimlInstanceRegistry.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Override public boolean cancel(String appName, String serverId, boolean isReplication) { try { final boolean out = (boolean) cancelMethodHandle.invokeWithArguments(this, appName, serverId, isReplication); handleCancelationMethod.invokeWithArguments(this, appName, serverId, isReplication); return out; } catch (ClassCastException | WrongMethodTypeException e) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, e); } catch (RuntimeException re) { throw re; } catch (Throwable t) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, t); } }
Example #28
Source File: ApimlInstanceRegistry.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Override public void register(final InstanceInfo info, final boolean isReplication) { try { register2ArgsMethodHandle.invokeWithArguments(this, info, isReplication); handleRegistrationMethod.invokeWithArguments(this, info, resolveInstanceLeaseDurationRewritten(info), isReplication); } catch (ClassCastException | WrongMethodTypeException e) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, e); } catch (RuntimeException re) { throw re; } catch (Throwable t) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, t); } }
Example #29
Source File: BigArityTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void testArities(Class<? extends Object[]> cls, int minArity, int maxArity, int iterations) throws Throwable { boolean verbose = (cls == Object[].class); for (int arity = minArity; arity <= maxArity; arity++) { if (verbose) System.out.println("arity="+arity); MethodHandle mh = MH_hashArguments(cls, arity); MethodHandle mh_VA = mh.asSpreader(cls, arity); assert(mh_VA.type().parameterType(0) == cls); testArities(cls, arity, iterations, verbose, mh, mh_VA); // mh_CA will collect arguments of a particular type and pass them to mh_VA MethodHandle mh_CA = mh_VA.asCollector(cls, arity); MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity); assert(mh_CA.type().equals(mh.type())); assert(mh_VA2.type().equals(mh_VA.type())); if (cls != Object[].class) { try { mh_VA2.invokeWithArguments(new Object[arity]); throw new AssertionError("should not reach"); } catch (ClassCastException | WrongMethodTypeException ex) { } } int iterations_VA = iterations / 100; testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2); } }
Example #30
Source File: ApimlInstanceRegistry.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Override public void register(InstanceInfo info, int leaseDuration, boolean isReplication) { try { register3ArgsMethodHandle.invokeWithArguments(this, info, leaseDuration, isReplication); handleRegistrationMethod.invokeWithArguments(this, info, leaseDuration, isReplication); } catch (ClassCastException | WrongMethodTypeException e) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, e); } catch (RuntimeException re) { throw re; } catch (Throwable t) { throw new IllegalArgumentException(EXCEPTION_MESSAGE, t); } }