diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index bf06b95c51c14fbac7b9b72508a301701880e17f..f597bc7f3e6a0d5d76d522cea1cfd78afb2dae50 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1609,17 +1609,10 @@ public class Attr extends JCTree.Visitor { tree.getTag() - JCTree.ASGOffset, owntype, operand); - if (types.isSameType(operator.type.getReturnType(), syms.stringType)) { - // String assignment; make sure the lhs is a string - chk.checkType(tree.lhs.pos(), - owntype, - syms.stringType); - } else { - chk.checkDivZero(tree.rhs.pos(), operator, operand); - chk.checkCastable(tree.rhs.pos(), - operator.type.getReturnType(), - owntype); - } + chk.checkDivZero(tree.rhs.pos(), operator, operand); + chk.checkCastable(tree.rhs.pos(), + operator.type.getReturnType(), + owntype); } result = check(tree, owntype, VAL, pkind, pt); } diff --git a/test/tools/javac/expression/ObjectAppend.java b/test/tools/javac/StringConversion2.java similarity index 73% rename from test/tools/javac/expression/ObjectAppend.java rename to test/tools/javac/StringConversion2.java index b92575f0d84799175683e7caa390327629909867..6e8db13e22dd920ac11f44e52b3eae5d0c78d79a 100644 --- a/test/tools/javac/expression/ObjectAppend.java +++ b/test/tools/javac/StringConversion2.java @@ -1,5 +1,5 @@ /* - * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,14 +23,17 @@ /* * @test - * @bug 4642850 - * @summary compiler allows Object += String - * @author gafter - * - * @compile/fail ObjectAppend.java + * @bug 4741726 + * @summary allow Object += String */ -class ObjectAppend {{ - Object o = null; - o += "string"; -}} +public class StringConversion2 +{ + public static void main(String[] args) { + Object o = "Hello "; + String s = "World!"; + o += s; + if (!o.equals("Hello World!")) + throw new Error("test failed"); + } +}