author | peytoia |
Fri, 08 Oct 2010 09:50:56 +0900 | |
changeset 6834 | 303c8cca4a31 |
permissions | -rw-r--r-- |
6834
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
1 |
/* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
4 |
* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
8 |
* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
13 |
* accompanied this code). |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
14 |
* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
18 |
* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
21 |
* questions. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
22 |
*/ |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
23 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
24 |
/* |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
25 |
* @test |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
26 |
* @bug 6970930 |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
27 |
* @summary verify that compare() throws NPE instead of IAE when an argument is null. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
28 |
*/ |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
29 |
import java.text.*; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
30 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
31 |
public class Bug6970930 { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
32 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
33 |
private static boolean err = false; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
34 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
35 |
public static void main(String[] args) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
36 |
// Check if compare() throws NPE. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
37 |
test1(null, null); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
38 |
test1("\"foo\"", null); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
39 |
test1(null, "\"bar\""); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
40 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
41 |
if (err) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
42 |
throw new RuntimeException("Failed."); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
43 |
} else { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
44 |
System.out.println("Passed."); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
45 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
46 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
47 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
48 |
private static void test1(String s1, String s2) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
49 |
RuleBasedCollator col = null; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
50 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
51 |
try { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
52 |
col = new RuleBasedCollator("< a < b"); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
53 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
54 |
catch (ParseException e) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
55 |
err = true; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
56 |
System.err.println(e); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
57 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
58 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
59 |
try { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
60 |
col.compare("foo", "bar"); // This line is necessary to reproduce the bug. |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
61 |
col.compare(s1, s2); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
62 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
63 |
err = true; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
64 |
System.err.println("No exception was thrown for compare(" + |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
65 |
s1 + ", " + s2 + ")."); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
66 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
67 |
catch (NullPointerException e) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
68 |
System.out.println("NPE was thrown as expected for compare(" + |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
69 |
s1 + ", " + s2 + ")."); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
70 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
71 |
catch (Exception e) { |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
72 |
err = true; |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
73 |
System.err.println("Unexpected exception was thrown for compare(" + |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
74 |
s1 + ", " + s2 + "): " + e); |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
75 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
76 |
} |
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
77 |
|
303c8cca4a31
6970930: RuleBasedCollator.compare(String,null) throws IAE (should be NPE)
peytoia
parents:
diff
changeset
|
78 |
} |