1.1 --- a/src/jdk/internal/dynalink/support/TypeUtilities.java Wed Jan 14 18:25:01 2015 +0100 1.2 +++ b/src/jdk/internal/dynalink/support/TypeUtilities.java Wed Jan 14 15:54:18 2015 +0100 1.3 @@ -118,17 +118,13 @@ 1.4 public static Class<?> getCommonLosslessConversionType(final Class<?> c1, final Class<?> c2) { 1.5 if(c1 == c2) { 1.6 return c1; 1.7 + } else if (c1 == void.class || c2 == void.class) { 1.8 + return Object.class; 1.9 } else if(isConvertibleWithoutLoss(c2, c1)) { 1.10 return c1; 1.11 } else if(isConvertibleWithoutLoss(c1, c2)) { 1.12 return c2; 1.13 - } 1.14 - if(c1 == void.class) { 1.15 - return c2; 1.16 - } else if(c2 == void.class) { 1.17 - return c1; 1.18 - } 1.19 - if(c1.isPrimitive() && c2.isPrimitive()) { 1.20 + } else if(c1.isPrimitive() && c2.isPrimitive()) { 1.21 if((c1 == byte.class && c2 == char.class) || (c1 == char.class && c2 == byte.class)) { 1.22 // byte + char = int 1.23 return int.class; 1.24 @@ -268,20 +264,24 @@ 1.25 } 1.26 1.27 /** 1.28 - * Determines whether a type can be converted to another without losing any 1.29 - * precision. 1.30 + * Determines whether a type can be converted to another without losing any precision. As a special case, 1.31 + * void is considered convertible only to Object and void, while anything can be converted to void. This 1.32 + * is because a target type of void means we don't care about the value, so the conversion is always 1.33 + * permissible. 1.34 * 1.35 * @param sourceType the source type 1.36 * @param targetType the target type 1.37 * @return true if lossless conversion is possible 1.38 */ 1.39 public static boolean isConvertibleWithoutLoss(final Class<?> sourceType, final Class<?> targetType) { 1.40 - if(targetType.isAssignableFrom(sourceType)) { 1.41 + if(targetType.isAssignableFrom(sourceType) || targetType == void.class) { 1.42 return true; 1.43 } 1.44 if(sourceType.isPrimitive()) { 1.45 if(sourceType == void.class) { 1.46 - return false; // Void can't be losslessly represented by any type 1.47 + // Void should be losslessly representable by Object, either as null or as a custom value that 1.48 + // can be set with DynamicLinkerFactory.setAutoConversionStrategy. 1.49 + return targetType == Object.class; 1.50 } 1.51 if(targetType.isPrimitive()) { 1.52 return isProperPrimitiveLosslessSubtype(sourceType, targetType);