author | duke |
Wed, 05 Jul 2017 22:06:37 +0200 | |
changeset 40471 | ad45133ff99e |
parent 38950 | 89fe9dae591e |
permissions | -rw-r--r-- |
38950
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
1 |
/* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
4 |
* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
8 |
* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
13 |
* accompanied this code). |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
14 |
* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
18 |
* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
21 |
* questions. |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
22 |
*/ |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
23 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
24 |
/* |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
25 |
* @test |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
26 |
* @bug 8135061 |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
27 |
* @summary Checks that the Locale.lookup executes properly without throwing |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
28 |
* any exception for some specific language ranges |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
29 |
* @run main Bug8135061 |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
30 |
*/ |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
31 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
32 |
import java.util.Collection; |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
33 |
import java.util.Collections; |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
34 |
import java.util.List; |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
35 |
import java.util.Locale; |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
36 |
import java.util.Locale.LanguageRange; |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
37 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
38 |
public class Bug8135061 { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
39 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
40 |
public static void main(String[] args) { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
41 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
42 |
/* lookup should run without throwing any exception and |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
43 |
* return null as the language range does not match with the language |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
44 |
* tag |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
45 |
*/ |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
46 |
List<LanguageRange> ranges = LanguageRange.parse("nv"); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
47 |
Collection<Locale> locales = Collections.singleton(Locale.ENGLISH); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
48 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
49 |
try { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
50 |
Locale match = Locale.lookup(ranges, locales); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
51 |
if (match != null) { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
52 |
throw new RuntimeException("Locale.lookup returned non-null: " |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
53 |
+ match); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
54 |
} |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
55 |
} catch (Exception ex) { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
56 |
throw new RuntimeException("[Locale.lookup failed on language" |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
57 |
+ " range: " + ranges + " and language tags " |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
58 |
+ locales + "]", ex); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
59 |
} |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
60 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
61 |
/* lookup should run without throwing any exception and |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
62 |
* return "nv" as the matching tag |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
63 |
*/ |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
64 |
ranges = LanguageRange.parse("i-navajo"); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
65 |
locales = Collections.singleton(new Locale("nv")); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
66 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
67 |
try { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
68 |
Locale match = Locale.lookup(ranges, locales); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
69 |
if (!match.toLanguageTag().equals("nv")) { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
70 |
throw new RuntimeException("Locale.lookup returned unexpected" |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
71 |
+ " result: " + match); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
72 |
} |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
73 |
} catch (Exception ex) { |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
74 |
throw new RuntimeException("[Locale.lookup failed on language" |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
75 |
+ " range: " + ranges + " and language tags " |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
76 |
+ locales + "]", ex); |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
77 |
} |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
78 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
79 |
} |
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
80 |
|
89fe9dae591e
8135061: java.util.Locale#lookup throws java.lang.StringIndexOutOfBoundsException for range having '-' as second character
nishjain
parents:
diff
changeset
|
81 |
} |