Thu, 06 Mar 2008 10:07:25 -0800
4741726: allow Object += String
Summary: remove code in line with restriction removed from JLS
Reviewed-by: mcimadamore
Contributed-by: michaelbailey0@gmail.com
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Mar 04 15:45:20 2008 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Mar 06 10:07:25 2008 -0800 1.3 @@ -1609,17 +1609,10 @@ 1.4 tree.getTag() - JCTree.ASGOffset, 1.5 owntype, 1.6 operand); 1.7 - if (types.isSameType(operator.type.getReturnType(), syms.stringType)) { 1.8 - // String assignment; make sure the lhs is a string 1.9 - chk.checkType(tree.lhs.pos(), 1.10 - owntype, 1.11 - syms.stringType); 1.12 - } else { 1.13 - chk.checkDivZero(tree.rhs.pos(), operator, operand); 1.14 - chk.checkCastable(tree.rhs.pos(), 1.15 - operator.type.getReturnType(), 1.16 - owntype); 1.17 - } 1.18 + chk.checkDivZero(tree.rhs.pos(), operator, operand); 1.19 + chk.checkCastable(tree.rhs.pos(), 1.20 + operator.type.getReturnType(), 1.21 + owntype); 1.22 } 1.23 result = check(tree, owntype, VAL, pkind, pt); 1.24 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/StringConversion2.java Thu Mar 06 10:07:25 2008 -0800 2.3 @@ -0,0 +1,39 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 4741726 2.30 + * @summary allow Object += String 2.31 + */ 2.32 + 2.33 +public class StringConversion2 2.34 +{ 2.35 + public static void main(String[] args) { 2.36 + Object o = "Hello "; 2.37 + String s = "World!"; 2.38 + o += s; 2.39 + if (!o.equals("Hello World!")) 2.40 + throw new Error("test failed"); 2.41 + } 2.42 +}
3.1 --- a/test/tools/javac/expression/ObjectAppend.java Tue Mar 04 15:45:20 2008 +0000 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,36 +0,0 @@ 3.4 -/* 3.5 - * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. 3.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 - * 3.8 - * This code is free software; you can redistribute it and/or modify it 3.9 - * under the terms of the GNU General Public License version 2 only, as 3.10 - * published by the Free Software Foundation. 3.11 - * 3.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 - * version 2 for more details (a copy is included in the LICENSE file that 3.16 - * accompanied this code). 3.17 - * 3.18 - * You should have received a copy of the GNU General Public License version 3.19 - * 2 along with this work; if not, write to the Free Software Foundation, 3.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 - * 3.22 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 - * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 - * have any questions. 3.25 - */ 3.26 - 3.27 -/* 3.28 - * @test 3.29 - * @bug 4642850 3.30 - * @summary compiler allows Object += String 3.31 - * @author gafter 3.32 - * 3.33 - * @compile/fail ObjectAppend.java 3.34 - */ 3.35 - 3.36 -class ObjectAppend {{ 3.37 - Object o = null; 3.38 - o += "string"; 3.39 -}}