TestOptimizeStringConcat.java revision 10049:73443d24e529
1294328Sdes/*
257429Smarkm * Copyright (c) 2015 SAP SE. All rights reserved.
3294328Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
457429Smarkm *
5294328Sdes * This code is free software; you can redistribute it and/or modify it
6294328Sdes * under the terms of the GNU General Public License version 2 only, as
7294328Sdes * published by the Free Software Foundation.
865674Skris *
9294328Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
10294328Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11294328Sdes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12294328Sdes * version 2 for more details (a copy is included in the LICENSE file that
13294328Sdes * accompanied this code).
14294328Sdes *
15294328Sdes * You should have received a copy of the GNU General Public License version
1657429Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1757429Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18294328Sdes *
19294328Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2057429Smarkm * or visit www.oracle.com if you need additional information or have any
2157429Smarkm * questions.
22162856Sdes */
23162856Sdes
24162856Sdes/*
2576262Sgreen * @test
26294328Sdes * @bug 8068909
2757429Smarkm * @key regression
28147005Sdes * @summary test that string optimizations produce code, that doesn't lead to a crash.
29294328Sdes * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestOptimizeStringConcat
30147005Sdes * @author axel.siebenborn@sap.com
31294328Sdes */
32147005Sdespublic class TestOptimizeStringConcat {
33294328Sdes
34294328Sdes    static boolean checkArgumentSyntax(String value, String allowedchars, String notallowedchars, String logmsg) {
35294328Sdes        String rc = null;
36294328Sdes
37294328Sdes        int maxchar = 99999;
38147005Sdes        int minchar = 1;
39147005Sdes        if ((allowedchars != null && notallowedchars != null) || minchar > maxchar) {
4098684Sdes            rc = "internal error";
4198684Sdes        } else {
4298684Sdes            if (value == null) {
43147005Sdes                rc = "the value null is not allowed, it is missing";
4499063Sdes            } else if (value != null && minchar > 0 && value.trim().equals("")) {
45147005Sdes                rc = "the value must not be empty";
46294328Sdes            } else if (value != null) {
47147005Sdes                if (value.length() < minchar || value.length() > maxchar) {
48147005Sdes                    if (rc == null) {
4998684Sdes                        rc = "the value length must be between +minchar+ and +maxchar";
5098684Sdes                    }
51147005Sdes                }
52294328Sdes                char[] _value = value.toCharArray();
53147005Sdes                boolean dotfound = false;
54294328Sdes                int i = 1;
55147005Sdes                if (_value[i] == '.' && !dotfound) {
56294328Sdes                    dotfound = true;
57294328Sdes                } else if (allowedchars != null && allowedchars.indexOf(_value[i]) == -1) {
58294328Sdes                    if (rc == null) {
59294328Sdes                        rc = "the value contains an illegal character: '" + _value[i] + "', only following characters are allowed: '+allowedchars+'";
60294328Sdes                    } else {
61147005Sdes                        rc += " / the value contains an illegal character: '" + _value[i] + "', only following characters are allowed: '+allowedchars+'";
62147005Sdes                    }
6376262Sgreen                } else if (notallowedchars != null && notallowedchars.indexOf(_value[i]) != -1) {
6457429Smarkm                    if (rc == null) {
6557429Smarkm                        rc = "the value contains an illegal character: '" + _value[i] + "', following characters are not allowed '+notallowedchars+'";
66147005Sdes                    } else {
6799063Sdes                        rc += " / the value contains an illegal character: '" + _value[i] + "', following characters are not allowed '+notallowedchars+'";
68147005Sdes                    }
69294328Sdes                }
70147005Sdes            }
71147005Sdes        }
7257429Smarkm
7357429Smarkm        if (rc != null) {
74147005Sdes            System.out.println(logmsg + " ==> " + rc);
75294328Sdes            return false;
76147005Sdes        }
77294328Sdes        return true;
78147005Sdes    }
79294328Sdes
80294328Sdes    public static void main(String[] args) {
81294328Sdes        boolean failed = false;
82294328Sdes        for (int i = 0; i < 10000; i++) {
83294328Sdes            failed |= !checkArgumentSyntax("theName", null, "\"<&", "Error consistencyCheck: name in component definition");
84147005Sdes            failed |= !checkArgumentSyntax(null, null, "\"<&", "Error consistencyCheck: name in component definition");
85147005Sdes            failed |= !checkArgumentSyntax("42", "0123456789.", null, "Error consistencyCheck: counter in component definition");
8676262Sgreen        }
8776262Sgreen        System.out.println(failed);
8876262Sgreen    }
89147005Sdes}
9099063Sdes