ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/TreeMap/HeadTailTypeError.java
Revision: 1.6
Committed: Sun Oct 22 02:59:18 2017 UTC (6 years, 7 months ago) by jsr166
Branch: MAIN
Changes since 1.5: +1 -1 lines
Log Message:
fix errorprone [MixedArrayDimensions] warnings

File Contents

# User Rev Content
1 jsr166 1.1 /*
2 jsr166 1.2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 jsr166 1.1 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19 jsr166 1.2 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20     * or visit www.oracle.com if you need additional information or have any
21     * questions.
22 jsr166 1.1 */
23    
24     /*
25 jsr166 1.5 * @test
26     * @bug 4251519 4251520
27     * @summary indexOf and lastIndex of used to let you look outside the
28     * valid range in the backing array
29 jsr166 1.1 */
30    
31     import java.util.*;
32    
33     public class HeadTailTypeError {
34 jsr166 1.6 public static void main(String[] args) throws Exception {
35 jsr166 1.3 try {
36 jsr166 1.1 SortedMap m = new TreeMap();
37     m.headMap(new Object());
38     throw new Exception("headMap, natural ordering");
39     } catch (ClassCastException e) {
40     }
41    
42 jsr166 1.3 try {
43 jsr166 1.1 SortedMap m = new TreeMap();
44     m.tailMap(new Object());
45     throw new Exception("tailMap, natural ordering");
46     } catch (ClassCastException e) {
47     }
48    
49 jsr166 1.3 try {
50 jsr166 1.1 SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
51     m.headMap(new Integer(0));
52     throw new Exception("headMap, explicit comparator");
53     } catch (ClassCastException e) {
54     }
55    
56 jsr166 1.3 try {
57 jsr166 1.1 SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
58     m.tailMap(new Integer(0));
59     throw new Exception("tailMap, explicit comparator");
60     } catch (ClassCastException e) {
61     }
62    
63 jsr166 1.3 try {
64 jsr166 1.1 SortedSet m = new TreeSet();
65     m.headSet(new Object());
66     throw new Exception("headSet, natural ordering");
67     } catch (ClassCastException e) {
68     }
69    
70 jsr166 1.3 try {
71 jsr166 1.1 SortedSet m = new TreeSet();
72     m.tailSet(new Object());
73     throw new Exception("tailSet, natural ordering");
74     } catch (ClassCastException e) {
75     }
76    
77 jsr166 1.3 try {
78 jsr166 1.1 SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
79     m.headSet(new Integer(0));
80     throw new Exception("headSet, explicit comparator");
81     } catch (ClassCastException e) {
82     }
83    
84 jsr166 1.3 try {
85 jsr166 1.1 SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
86     m.tailSet(new Integer(0));
87     throw new Exception("tailSet, explicit comparator");
88     } catch (ClassCastException e) {
89     }
90    
91 jsr166 1.3 try {
92 jsr166 1.1 SortedMap m = new TreeMap();
93     m.headMap(null);
94     throw new Exception("(null endpoint)headMap, natural ordering");
95     } catch (NullPointerException e) {
96     }
97    
98 jsr166 1.3 try {
99 jsr166 1.1 SortedMap m = new TreeMap();
100     m.tailMap(null);
101     throw new Exception("(null endpoint)tailMap, natural ordering");
102     } catch (NullPointerException e) {
103     }
104    
105    
106 jsr166 1.3 try {
107 jsr166 1.1 SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
108     m.headMap(null);
109     throw new Exception("(null endpoint)headMap, explicit comparator");
110     } catch (NullPointerException e) {
111     }
112    
113 jsr166 1.3 try {
114 jsr166 1.1 SortedMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
115     m.tailMap(null);
116     throw new Exception("(null endpoint)tailMap, explicit comparator");
117     } catch (NullPointerException e) {
118     }
119    
120 jsr166 1.3 try {
121 jsr166 1.1 SortedSet m = new TreeSet();
122     m.headSet(null);
123     throw new Exception("(null endpoint)headSet, natural ordering");
124     } catch (NullPointerException e) {
125     }
126    
127 jsr166 1.3 try {
128 jsr166 1.1 SortedSet m = new TreeSet();
129     m.tailSet(null);
130     throw new Exception("(null endpoint)tailSet, natural ordering");
131     } catch (NullPointerException e) {
132     }
133    
134 jsr166 1.3 try {
135 jsr166 1.1 SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
136     m.headSet(null);
137     throw new Exception("(null endpoint)headSet, explicit comparator");
138     } catch (NullPointerException e) {
139     }
140    
141 jsr166 1.3 try {
142 jsr166 1.1 SortedSet m = new TreeSet(String.CASE_INSENSITIVE_ORDER);
143     m.tailSet(null);
144     throw new Exception("(null endpoint)tailSet, explicit comparator");
145     } catch (NullPointerException e) {
146     }
147    
148     // These should not fail
149     SortedMap m = new TreeMap();
150     m.headMap(new Integer(0));
151     m.tailMap(new Integer(0));
152     m = new TreeMap(String.CASE_INSENSITIVE_ORDER);
153     m.headMap("llama");
154     m.tailMap("llama");
155    
156     SortedSet s = new TreeSet();
157     s.headSet(new Integer(0));
158     s.tailSet(new Integer(0));
159     s = new TreeSet(String.CASE_INSENSITIVE_ORDER);
160     s.headSet("drama");
161     s.tailSet("drama");
162     }
163     }