Path: blob/master/test/jdk/java/lang/String/concat/StringConcatFactoryRepeatedConstants.java
41153 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.lang.invoke.CallSite;24import java.lang.invoke.MethodHandles;25import java.lang.invoke.MethodType;26import java.lang.invoke.StringConcatFactory;2728/**29* @test30* @summary StringConcatFactory allow recipes with repeated constants, but this31* is not expressible with java code and needs an explicit sanity test32* @bug 822285233*34* @compile StringConcatFactoryRepeatedConstants.java35*36* @run main/othervm -Xverify:all StringConcatFactoryRepeatedConstants37*/38public class StringConcatFactoryRepeatedConstants {3940public static void main(String[] args) throws Throwable {4142CallSite site = StringConcatFactory.makeConcatWithConstants(43MethodHandles.lookup(),44"foo",45MethodType.methodType(String.class),46"\u0002\u0002",47"foo", "bar"48);49String string = (String)site.dynamicInvoker().invoke();50if (!"foobar".equals(string)) {51throw new IllegalStateException("Expected: foobar, got: " + string);52}5354site = StringConcatFactory.makeConcatWithConstants(55MethodHandles.lookup(),56"foo",57MethodType.methodType(String.class),58"\u0002\u0002test\u0002\u0002",59"foo", 17.0f, 4711L, "bar"60);61string = (String)site.dynamicInvoker().invoke();62StringBuilder sb = new StringBuilder();63sb.append("foo").append(17.0f).append("test").append(4711L).append("bar");64if (!sb.toString().equals(string)) {65throw new IllegalStateException("Expected: " + sb.toString() + ", got: " + string);66}67}6869}707172