On Wed, 28 Oct 2020 13:32:19 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
>>> >>> >>> Seems like a reasonable change. Is there an already existing test for "bad" >>> permute args that could be expanded to discern the new exception message? >> >> There are several tests for permuteArguments, but none that explicitly test >> this failure. I'll add some (good idea). > > I've added some negative tests that test for the different failure conditions. Thanks for adding additional test coverage @JornVernee. Writing a tight implementation of assertThrows is non-trivial - I'm not sure that the version you have will fail if the exception is not thrown? Either way maybe we can reuse some of the junit machinery for this purpose, e.g.: static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; public void testReorderTypeMismatch() throws Throwable { MethodHandle mh = MethodHandles.empty(MethodType.methodType(void.class, int.class, int.class, String.class)); MethodType newType = MethodType.methodType(void.class, double.class, String.class); var exception = expectThrows(IAE, () -> MethodHandles.permuteArguments(mh, newType, 0, 0, 1)); assertMatches(exception.getMessage(), ".*parameter types do not match after reorder.*"); } private static void assertMatches(String str, String pattern) { if (!str.matches(pattern)) { throw new AssertionError("'" + str + "' did not match the pattern '" + pattern + "'."); } } ------------- PR: https://git.openjdk.java.net/jdk/pull/878