src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff src/java.base/share/classes/java/lang/invoke

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
rev 11011 : 8066746: MHs.explicitCastArguments does incorrect type checks for VarargsCollector
Reviewed-by: ?


2011      *     the low-order bit.
2012      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2013      *     and if the reference is null at runtime, a zero value is introduced.
2014      * </ul>
2015      * @param target the method handle to invoke after arguments are retyped
2016      * @param newType the expected type of the new method handle
2017      * @return a method handle which delegates to the target after performing
2018      *           any necessary argument conversions, and arranges for any
2019      *           necessary return value conversions
2020      * @throws NullPointerException if either argument is null
2021      * @throws WrongMethodTypeException if the conversion cannot be made
2022      * @see MethodHandle#asType
2023      */
2024     public static
2025     MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2026         explicitCastArgumentsChecks(target, newType);
2027         // use the asTypeCache when possible:
2028         MethodType oldType = target.type();
2029         if (oldType == newType)  return target;
2030         if (oldType.explicitCastEquivalentToAsType(newType)) {
2031             return target.asType(newType);
2032         }
2033         return MethodHandleImpl.makePairwiseConvert(target, newType, false);
2034     }
2035 
2036     private static void explicitCastArgumentsChecks(MethodHandle target, MethodType newType) {
2037         if (target.type().parameterCount() != newType.parameterCount()) {
2038             throw new WrongMethodTypeException("cannot explicitly cast " + target + " to " + newType);
2039         }
2040     }
2041 
2042     /**
2043      * Produces a method handle which adapts the calling sequence of the
2044      * given method handle to a new type, by reordering the arguments.
2045      * The resulting method handle is guaranteed to report a type
2046      * which is equal to the desired new type.
2047      * <p>
2048      * The given array controls the reordering.
2049      * Call {@code #I} the number of incoming parameters (the value
2050      * {@code newType.parameterCount()}, and call {@code #O} the number
2051      * of outgoing parameters (the value {@code target.type().parameterCount()}).




2011      *     the low-order bit.
2012      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2013      *     and if the reference is null at runtime, a zero value is introduced.
2014      * </ul>
2015      * @param target the method handle to invoke after arguments are retyped
2016      * @param newType the expected type of the new method handle
2017      * @return a method handle which delegates to the target after performing
2018      *           any necessary argument conversions, and arranges for any
2019      *           necessary return value conversions
2020      * @throws NullPointerException if either argument is null
2021      * @throws WrongMethodTypeException if the conversion cannot be made
2022      * @see MethodHandle#asType
2023      */
2024     public static
2025     MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2026         explicitCastArgumentsChecks(target, newType);
2027         // use the asTypeCache when possible:
2028         MethodType oldType = target.type();
2029         if (oldType == newType)  return target;
2030         if (oldType.explicitCastEquivalentToAsType(newType)) {
2031             return target.asFixedArity().asType(newType);
2032         }
2033         return MethodHandleImpl.makePairwiseConvert(target, newType, false);
2034     }
2035 
2036     private static void explicitCastArgumentsChecks(MethodHandle target, MethodType newType) {
2037         if (target.type().parameterCount() != newType.parameterCount()) {
2038             throw new WrongMethodTypeException("cannot explicitly cast " + target + " to " + newType);
2039         }
2040     }
2041 
2042     /**
2043      * Produces a method handle which adapts the calling sequence of the
2044      * given method handle to a new type, by reordering the arguments.
2045      * The resulting method handle is guaranteed to report a type
2046      * which is equal to the desired new type.
2047      * <p>
2048      * The given array controls the reordering.
2049      * Call {@code #I} the number of incoming parameters (the value
2050      * {@code newType.parameterCount()}, and call {@code #O} the number
2051      * of outgoing parameters (the value {@code target.type().parameterCount()}).


src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File