--- old/src/java.base/share/classes/java/lang/invoke/MethodHandle.java 2014-09-05 17:12:38.000000000 +0400 +++ new/src/java.base/share/classes/java/lang/invoke/MethodHandle.java 2014-09-05 17:12:37.000000000 +0400 @@ -1315,9 +1315,27 @@ } /*non-public*/ - MethodHandle viewAsType(MethodType newType) { + MethodHandle viewAsType(MethodType newType, boolean strict) { // No actual conversions, just a new view of the same method. - return MethodHandleImpl.makePairwiseConvert(this, newType, 0); + // Note that this operation must not produce a DirectMethodHandle, + // because retyped DMHs, like any transformed MHs, + // cannot be cracked into MethodHandleInfo. + assert viewAsTypeChecks(newType, strict); + BoundMethodHandle mh = rebind(); + assert(!((MethodHandle)mh instanceof DirectMethodHandle)); + return mh.copyWith(newType, mh.form); + } + + /*non-public*/ + boolean viewAsTypeChecks(MethodType newType, boolean strict) { + if (strict) { + assert(type().isViewableAs(newType, true)) + : Arrays.asList(this, newType); + } else { + assert(type().basicType().isViewableAs(newType.basicType(), true)) + : Arrays.asList(this, newType); + } + return true; } // Decoding @@ -1373,6 +1391,9 @@ //// All these methods assume arguments are already validated. /*non-public*/ + abstract MethodHandle copyWith(MethodType mt, LambdaForm lf); + + /*non-public*/ BoundMethodHandle rebind() { // Bind 'this' into a new invoker, of the known class BMH. MethodType type2 = type();