1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon Apr 25 15:50:30 2011 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Apr 25 15:56:09 2011 -0700 1.3 @@ -74,8 +74,9 @@ 1.4 final JavacMessages messages; 1.5 final Names names; 1.6 final boolean allowBoxing; 1.7 + final boolean allowCovariantReturns; 1.8 + final boolean allowObjectToPrimitiveCast; 1.9 final ClassReader reader; 1.10 - final Source source; 1.11 final Check chk; 1.12 List<Warner> warnStack = List.nil(); 1.13 final Name capturedName; 1.14 @@ -92,9 +93,11 @@ 1.15 context.put(typesKey, this); 1.16 syms = Symtab.instance(context); 1.17 names = Names.instance(context); 1.18 - allowBoxing = Source.instance(context).allowBoxing(); 1.19 + Source source = Source.instance(context); 1.20 + allowBoxing = source.allowBoxing(); 1.21 + allowCovariantReturns = source.allowCovariantReturns(); 1.22 + allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); 1.23 reader = ClassReader.instance(context); 1.24 - source = Source.instance(context); 1.25 chk = Check.instance(context); 1.26 capturedName = names.fromString("<captured wildcard>"); 1.27 messages = JavacMessages.instance(context); 1.28 @@ -949,8 +952,9 @@ 1.29 return true; 1.30 1.31 if (t.isPrimitive() != s.isPrimitive()) 1.32 - return allowBoxing && (isConvertible(t, s, warn) || isConvertible(s, t, warn)); 1.33 - 1.34 + return allowBoxing && ( 1.35 + isConvertible(t, s, warn) 1.36 + || (allowObjectToPrimitiveCast && isConvertible(s, t, warn))); 1.37 if (warn != warnStack.head) { 1.38 try { 1.39 warnStack = warnStack.prepend(warn); 1.40 @@ -3070,7 +3074,7 @@ 1.41 1.42 if (hasSameArgs(r1, r2)) 1.43 return covariantReturnType(r1.getReturnType(), r2res, warner); 1.44 - if (!source.allowCovariantReturns()) 1.45 + if (!allowCovariantReturns) 1.46 return false; 1.47 if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner)) 1.48 return true; 1.49 @@ -3087,7 +3091,7 @@ 1.50 public boolean covariantReturnType(Type t, Type s, Warner warner) { 1.51 return 1.52 isSameType(t, s) || 1.53 - source.allowCovariantReturns() && 1.54 + allowCovariantReturns && 1.55 !t.isPrimitive() && 1.56 !s.isPrimitive() && 1.57 isAssignable(t, s, warner); 1.58 @@ -3293,7 +3297,7 @@ 1.59 } 1.60 if (giveWarning && !isReifiable(reverse ? from : to)) 1.61 warn.warn(LintCategory.UNCHECKED); 1.62 - if (!source.allowCovariantReturns()) 1.63 + if (!allowCovariantReturns) 1.64 // reject if there is a common method signature with 1.65 // incompatible return types. 1.66 chk.checkCompatibleAbstracts(warn.pos(), from, to); 1.67 @@ -3320,7 +3324,7 @@ 1.68 Type t2 = to; 1.69 if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments())) 1.70 return false; 1.71 - if (!source.allowCovariantReturns()) 1.72 + if (!allowCovariantReturns) 1.73 // reject if there is a common method signature with 1.74 // incompatible return types. 1.75 chk.checkCompatibleAbstracts(warn.pos(), from, to);