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

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

Print this page
rev 10755 : 8060483: NPE with explicitCastArguments unboxing null
Reviewed-by: ?

*** 887,916 **** * Narrowing like {@code long->byte} and basic-typing like {@code boolean->int} * are not supported by asType, but anything supported by asType is equivalent * with MHs.eCE. * 3a. unboxing conversions can be followed by the full matrix of primitive conversions * 3b. unboxing of null is permitted (creates a zero primitive value) - * Most unboxing conversions, like {@code Object->int}, has potentially - * different behaviors for asType vs. MHs.eCE, because the dynamic value - * might be a wrapper of a type that requires narrowing, like {@code (Object)1L->byte}. - * The equivalence is only certain if the static src type is a wrapper, - * and the conversion will be a widening one. * Other than interfaces, reference-to-reference conversions are the same. * Boxing primitives to references is the same for both operators. */ private static boolean explicitCastEquivalentToAsType(Class<?> src, Class<?> dst) { if (src == dst || dst == Object.class || dst == void.class) return true; if (src.isPrimitive()) { // Could be a prim/prim conversion, where casting is a strict superset. // Or a boxing conversion, which is always to an exact wrapper class. return canConvert(src, dst); } else if (dst.isPrimitive()) { ! Wrapper dw = Wrapper.forPrimitiveType(dst); ! // Watch out: If src is Number or Object, we could get dynamic narrowing conversion. ! // The conversion is known to be widening only if the wrapper type is statically visible. ! return (Wrapper.isWrapperType(src) && ! dw.isConvertibleFrom(Wrapper.forWrapperType(src))); } else { // R->R always works, but we have to avoid a check-cast to an interface. return !dst.isInterface() || dst.isAssignableFrom(src); } } --- 887,908 ---- * Narrowing like {@code long->byte} and basic-typing like {@code boolean->int} * are not supported by asType, but anything supported by asType is equivalent * with MHs.eCE. * 3a. unboxing conversions can be followed by the full matrix of primitive conversions * 3b. unboxing of null is permitted (creates a zero primitive value) * Other than interfaces, reference-to-reference conversions are the same. * Boxing primitives to references is the same for both operators. */ private static boolean explicitCastEquivalentToAsType(Class<?> src, Class<?> dst) { if (src == dst || dst == Object.class || dst == void.class) return true; if (src.isPrimitive()) { // Could be a prim/prim conversion, where casting is a strict superset. // Or a boxing conversion, which is always to an exact wrapper class. return canConvert(src, dst); } else if (dst.isPrimitive()) { ! // Unboxing behavior is different between MHs.eCA & MH.asType (see 3b). ! return false; } else { // R->R always works, but we have to avoid a check-cast to an interface. return !dst.isInterface() || dst.isAssignableFrom(src); } }
src/java.base/share/classes/java/lang/invoke/MethodType.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File