/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4030173 4071548
* @summary Verify correct conversion of non-string arguments in string concatenation.
* @author maddox
*
* @compile StringConversion.java
* @run main StringConversion
*/
class FooBar {
return null;
}
}
public class StringConversion {
throws Exception {
}
}
String s;
// Null reference must be converted to "null"
// Conversion will be done by 'StringBuffer.append'.
s = "foo" + n;
s = n + "bar";
s = "foo" + o;
s = o + "bar";
// Conversion will be done by 'String.valueOf'.
s = "" + n;
s = n + "";
s = "" + o;
s = o + "";
// Null 'toString' result must be converted to "null"
// Conversion will be done by 'StringBuffer.append'.
s = "foo" + m;
s = m + "bar";
// Conversion will be done by 'String.valueOf'.
s = "" + m;
s = m + "";
// A character array must be converted as if by
// 'toString', i.e., it is treated as an 'Object'.
s = "polymorph";
}
}