KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > exceptions > ExceptionTestUtility


1 package soot.toolkits.exceptions;
2
3 import soot.*;
4 import java.util.*;
5
6 /**
7  * Class which packages together some objects useful in
8  * unit tests of exception handling.
9  */

10 public class ExceptionTestUtility {
11
12     // Individual Throwable types for our tests:
13
final RefType THROWABLE;
14     final RefType EXCEPTION;
15     final RefType RUNTIME_EXCEPTION;
16     final RefType ARITHMETIC_EXCEPTION;
17     final RefType ARRAY_STORE_EXCEPTION;
18     final RefType CLASS_CAST_EXCEPTION ;
19     final RefType ILLEGAL_MONITOR_STATE_EXCEPTION;
20     final RefType INDEX_OUT_OF_BOUNDS_EXCEPTION;
21     final RefType ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION;
22     final RefType STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION;
23     final RefType NEGATIVE_ARRAY_SIZE_EXCEPTION;
24     final RefType NULL_POINTER_EXCEPTION;
25     final RefType ERROR;
26     final RefType LINKAGE_ERROR;
27     final RefType CLASS_CIRCULARITY_ERROR;
28     final RefType CLASS_FORMAT_ERROR;
29     final RefType UNSUPPORTED_CLASS_VERSION_ERROR;
30     final RefType EXCEPTION_IN_INITIALIZER_ERROR;
31     final RefType INCOMPATIBLE_CLASS_CHANGE_ERROR;
32     final RefType ABSTRACT_METHOD_ERROR;
33     final RefType ILLEGAL_ACCESS_ERROR;
34     final RefType INSTANTIATION_ERROR;
35     final RefType NO_SUCH_FIELD_ERROR;
36     final RefType NO_SUCH_METHOD_ERROR;
37     final RefType NO_CLASS_DEF_FOUND_ERROR;
38     final RefType UNSATISFIED_LINK_ERROR;
39     final RefType VERIFY_ERROR;
40     final RefType THREAD_DEATH;
41     final RefType VIRTUAL_MACHINE_ERROR;
42     final RefType INTERNAL_ERROR;
43     final RefType OUT_OF_MEMORY_ERROR;
44     final RefType STACK_OVERFLOW_ERROR;
45     final RefType UNKNOWN_ERROR;
46     final RefType AWT_ERROR;
47     final RefType UNDECLARED_THROWABLE_EXCEPTION;
48     final RefType UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION;
49
50     // The universe of all Throwable types for our tests:
51
final Set ALL_TEST_THROWABLES;
52
53     // Set that matches the representation of all Throwables used
54
// internally by ThrowableSet:
55
final Set ALL_THROWABLES_REP;
56
57     // Some useful subsets of our Throwable universe:
58
final Set VM_ERRORS;
59     final Set VM_ERRORS_PLUS_SUPERTYPES;
60     final Set VM_AND_RESOLVE_CLASS_ERRORS;
61     final Set VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES;
62     final Set VM_AND_RESOLVE_FIELD_ERRORS;
63     final Set VM_AND_RESOLVE_FIELD_ERRORS_PLUS_SUPERTYPES;
64     final Set VM_AND_RESOLVE_METHOD_ERRORS;
65     final Set VM_AND_RESOLVE_METHOD_ERRORS_PLUS_SUPERTYPES;
66     final Set ALL_TEST_ERRORS;
67     final Set ALL_TEST_ERRORS_PLUS_SUPERTYPES;
68     final Set PERENNIAL_THROW_EXCEPTIONS;
69     final Set PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES;
70     final Set THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE;
71     final Set THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUPERTYPES;
72     final Set THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES;
73     final Set THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES;
74
75     // Sets that match the representations of subsets of Errors used
76
// internally by ThrowableSet:
77
final Set VM_AND_RESOLVE_CLASS_ERRORS_REP;
78     final Set VM_AND_RESOLVE_FIELD_ERRORS_REP;
79     final Set VM_AND_RESOLVE_METHOD_ERRORS_REP;
80     final Set ALL_ERRORS_REP;
81
82     ExceptionTestUtility(String JavaDoc pathToJavaLib) {
83     Scene.v().setSootClassPath(pathToJavaLib);
84
85     THROWABLE = Scene.v().getRefType("java.lang.Throwable");
86
87     ERROR = Scene.v().getRefType("java.lang.Error");
88
89     Scene.v().loadClassAndSupport("java.lang.Exception");
90     EXCEPTION = Scene.v().getRefType("java.lang.Exception");
91
92     // runtime exceptions.
93
RUNTIME_EXCEPTION
94         = Scene.v().getRefType("java.lang.RuntimeException");
95
96     ARITHMETIC_EXCEPTION
97         = Scene.v().getRefType("java.lang.ArithmeticException");
98
99     ARRAY_STORE_EXCEPTION
100         = Scene.v().getRefType("java.lang.ArrayStoreException");
101
102     CLASS_CAST_EXCEPTION
103         = Scene.v().getRefType("java.lang.ClassCastException");
104
105     ILLEGAL_MONITOR_STATE_EXCEPTION
106         = Scene.v().getRefType("java.lang.IllegalMonitorStateException");
107
108     INDEX_OUT_OF_BOUNDS_EXCEPTION
109         = Scene.v().getRefType("java.lang.IndexOutOfBoundsException");
110
111     ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
112         = Scene.v().getRefType("java.lang.ArrayIndexOutOfBoundsException");
113
114     Scene.v().loadClassAndSupport("java.lang.StringIndexOutOfBoundsException");
115     STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION
116         = Scene.v().getRefType("java.lang.StringIndexOutOfBoundsException");
117
118     NEGATIVE_ARRAY_SIZE_EXCEPTION
119         = Scene.v().getRefType("java.lang.NegativeArraySizeException");
120
121     NULL_POINTER_EXCEPTION
122         = Scene.v().getRefType("java.lang.NullPointerException");
123
124     // linkage errors.
125
LINKAGE_ERROR = Scene.v().getRefType("java.lang.LinkageError");
126
127     CLASS_CIRCULARITY_ERROR
128         = Scene.v().getRefType("java.lang.ClassCircularityError");
129
130     CLASS_FORMAT_ERROR
131         = Scene.v().getRefType("java.lang.ClassFormatError");
132
133     Scene.v().loadClassAndSupport("java.lang.UnsupportedClassVersionError");
134     UNSUPPORTED_CLASS_VERSION_ERROR
135             = Scene.v().getRefType("java.lang.UnsupportedClassVersionError");
136
137     EXCEPTION_IN_INITIALIZER_ERROR
138         = Scene.v().getRefType("java.lang.ExceptionInInitializerError");
139
140     INCOMPATIBLE_CLASS_CHANGE_ERROR
141         = Scene.v().getRefType("java.lang.IncompatibleClassChangeError");
142
143     ABSTRACT_METHOD_ERROR
144         = Scene.v().getRefType("java.lang.AbstractMethodError");
145
146     ILLEGAL_ACCESS_ERROR
147         = Scene.v().getRefType("java.lang.IllegalAccessError");
148
149     INSTANTIATION_ERROR
150         = Scene.v().getRefType("java.lang.InstantiationError");
151
152     NO_SUCH_FIELD_ERROR
153         = Scene.v().getRefType("java.lang.NoSuchFieldError");
154
155     NO_SUCH_METHOD_ERROR
156         = Scene.v().getRefType("java.lang.NoSuchMethodError");
157
158     NO_CLASS_DEF_FOUND_ERROR
159         = Scene.v().getRefType("java.lang.NoClassDefFoundError");
160
161     UNSATISFIED_LINK_ERROR
162         = Scene.v().getRefType("java.lang.UnsatisfiedLinkError");
163
164     VERIFY_ERROR
165         = Scene.v().getRefType("java.lang.VerifyError");
166
167     // Token non-linkage Error (in the sense that it is not among
168
// Errors that the VM might throw itself during linkage---any
169
// error could be generated during linking by a static
170
// initializer).
171
Scene.v().loadClassAndSupport("java.awt.AWTError");
172     AWT_ERROR = Scene.v().getRefType("java.awt.AWTError");
173
174     // VM errors:
175
INTERNAL_ERROR
176         = Scene.v().getRefType("java.lang.InternalError");
177
178     OUT_OF_MEMORY_ERROR
179         = Scene.v().getRefType("java.lang.OutOfMemoryError");
180
181     STACK_OVERFLOW_ERROR
182         = Scene.v().getRefType("java.lang.StackOverflowError");
183
184     UNKNOWN_ERROR
185         = Scene.v().getRefType("java.lang.UnknownError");
186
187     THREAD_DEATH
188         = Scene.v().getRefType("java.lang.ThreadDeath");
189
190     Scene.v().loadClassAndSupport("java.lang.VirtualMachineError");
191     VIRTUAL_MACHINE_ERROR
192         = Scene.v().getRefType("java.lang.VirtualMachineError");
193
194     // Two Throwables that our test statements will never throw (except
195
// for invoke statements--in the absence of interprocedural analysis,
196
// we have to assume they can throw anything).
197
Scene.v().loadClassAndSupport("java.lang.reflect.UndeclaredThrowableException");
198     UNDECLARED_THROWABLE_EXCEPTION
199         = Scene.v().getRefType("java.lang.reflect.UndeclaredThrowableException");
200
201     Scene.v().loadClassAndSupport("javax.swing.UnsupportedLookAndFeelException");
202     UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION
203         = Scene.v().getRefType("javax.swing.UnsupportedLookAndFeelException");
204     
205     VM_ERRORS = Collections.unmodifiableSet(
206         new ExceptionHashSet(Arrays.asList(new RefType[] {
207         THREAD_DEATH,
208         INTERNAL_ERROR,
209         OUT_OF_MEMORY_ERROR,
210         STACK_OVERFLOW_ERROR,
211         UNKNOWN_ERROR,
212         })));
213
214     Set temp = new ExceptionHashSet(VM_ERRORS);
215     temp.add(VIRTUAL_MACHINE_ERROR);
216     temp.add(ERROR);
217     temp.add(THROWABLE);
218     VM_ERRORS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
219
220     temp = new ExceptionHashSet(VM_ERRORS);
221     temp.add(CLASS_CIRCULARITY_ERROR);
222     temp.add(ILLEGAL_ACCESS_ERROR);
223     temp.add(INCOMPATIBLE_CLASS_CHANGE_ERROR);
224     temp.add(LINKAGE_ERROR);
225     temp.add(NO_CLASS_DEF_FOUND_ERROR);
226     temp.add(VERIFY_ERROR);
227     Set tempForRep = new ExceptionHashSet(temp);
228     tempForRep.add(AnySubType.v(CLASS_FORMAT_ERROR));
229     VM_AND_RESOLVE_CLASS_ERRORS_REP = Collections.unmodifiableSet(tempForRep);
230
231     temp.add(CLASS_FORMAT_ERROR);
232     temp.add(UNSUPPORTED_CLASS_VERSION_ERROR);
233     VM_AND_RESOLVE_CLASS_ERRORS = Collections.unmodifiableSet(temp);
234     temp.add(VIRTUAL_MACHINE_ERROR);
235     temp.add(ERROR);
236     temp.add(THROWABLE);
237     VM_AND_RESOLVE_CLASS_ERRORS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
238
239     temp = new ExceptionHashSet(VM_AND_RESOLVE_CLASS_ERRORS_REP);
240     temp.add(NO_SUCH_FIELD_ERROR);
241     VM_AND_RESOLVE_FIELD_ERRORS_REP = Collections.unmodifiableSet(temp);
242
243     temp = new ExceptionHashSet(VM_AND_RESOLVE_CLASS_ERRORS);
244     temp.add(NO_SUCH_FIELD_ERROR);
245     VM_AND_RESOLVE_FIELD_ERRORS = Collections.unmodifiableSet(temp);
246     temp.add(VIRTUAL_MACHINE_ERROR);
247     temp.add(ERROR);
248     temp.add(THROWABLE);
249     VM_AND_RESOLVE_FIELD_ERRORS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
250     
251     temp = new ExceptionHashSet(VM_AND_RESOLVE_CLASS_ERRORS_REP);
252     temp.add(ABSTRACT_METHOD_ERROR);
253     temp.add(NO_SUCH_METHOD_ERROR);
254     temp.add(UNSATISFIED_LINK_ERROR);
255     VM_AND_RESOLVE_METHOD_ERRORS_REP = Collections.unmodifiableSet(temp);
256
257     temp = new ExceptionHashSet(VM_AND_RESOLVE_CLASS_ERRORS);
258     temp.add(ABSTRACT_METHOD_ERROR);
259     temp.add(NO_SUCH_METHOD_ERROR);
260     temp.add(UNSATISFIED_LINK_ERROR);
261     VM_AND_RESOLVE_METHOD_ERRORS = Collections.unmodifiableSet(temp);
262     temp.add(VIRTUAL_MACHINE_ERROR);
263     temp.add(ERROR);
264     temp.add(THROWABLE);
265     VM_AND_RESOLVE_METHOD_ERRORS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
266
267     temp = new ExceptionHashSet();
268     temp.add(AnySubType.v(Scene.v().getRefType("java.lang.Error")));
269     ALL_ERRORS_REP = Collections.unmodifiableSet(temp);
270
271     temp = new ExceptionHashSet(VM_AND_RESOLVE_METHOD_ERRORS);
272     temp.add(NO_SUCH_FIELD_ERROR);
273     temp.add(EXCEPTION_IN_INITIALIZER_ERROR);
274     temp.add(INSTANTIATION_ERROR);
275     temp.add(AWT_ERROR);
276     ALL_TEST_ERRORS = Collections.unmodifiableSet(temp);
277     
278     temp = new ExceptionHashSet(ALL_TEST_ERRORS);
279     temp.add(VIRTUAL_MACHINE_ERROR);
280     temp.add(ERROR);
281     temp.add(THROWABLE);
282     ALL_TEST_ERRORS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
283
284     temp = new ExceptionHashSet(VM_ERRORS);
285     temp.add(ILLEGAL_MONITOR_STATE_EXCEPTION);
286     temp.add(NULL_POINTER_EXCEPTION);
287     PERENNIAL_THROW_EXCEPTIONS = Collections.unmodifiableSet(temp);
288
289     temp = new ExceptionHashSet(VM_ERRORS_PLUS_SUPERTYPES);
290     temp.add(ILLEGAL_MONITOR_STATE_EXCEPTION);
291     temp.add(NULL_POINTER_EXCEPTION);
292     temp.add(RUNTIME_EXCEPTION);
293     temp.add(EXCEPTION);
294     PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
295
296     temp = new ExceptionHashSet(PERENNIAL_THROW_EXCEPTIONS);
297     temp.add(INCOMPATIBLE_CLASS_CHANGE_ERROR);
298     THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE = Collections.unmodifiableSet(temp);
299
300     temp = new ExceptionHashSet(PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES);
301     temp.add(INCOMPATIBLE_CLASS_CHANGE_ERROR);
302     temp.add(LINKAGE_ERROR);
303     THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUPERTYPES = Collections.unmodifiableSet(temp);
304
305     temp = new ExceptionHashSet(THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE);
306     temp.add(ABSTRACT_METHOD_ERROR);
307     temp.add(ILLEGAL_ACCESS_ERROR);
308     temp.add(INSTANTIATION_ERROR);;
309     temp.add(NO_SUCH_FIELD_ERROR);
310     temp.add(NO_SUCH_METHOD_ERROR);
311     THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES
312         = Collections.unmodifiableSet(temp);
313
314     temp = new ExceptionHashSet(THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUPERTYPES);
315     temp.add(ABSTRACT_METHOD_ERROR);
316     temp.add(ILLEGAL_ACCESS_ERROR);
317     temp.add(INSTANTIATION_ERROR);;
318     temp.add(NO_SUCH_FIELD_ERROR);
319     temp.add(NO_SUCH_METHOD_ERROR);
320     THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES
321         = Collections.unmodifiableSet(temp);
322     
323     temp = new ExceptionHashSet(Arrays.asList(new RefType[] {
324         THROWABLE,
325         EXCEPTION,
326         RUNTIME_EXCEPTION,
327         ARITHMETIC_EXCEPTION,
328         ARRAY_STORE_EXCEPTION,
329         CLASS_CAST_EXCEPTION ,
330         ILLEGAL_MONITOR_STATE_EXCEPTION,
331         INDEX_OUT_OF_BOUNDS_EXCEPTION,
332         ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION,
333         STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION,
334         NEGATIVE_ARRAY_SIZE_EXCEPTION,
335         NULL_POINTER_EXCEPTION,
336         ERROR,
337         LINKAGE_ERROR,
338         CLASS_CIRCULARITY_ERROR,
339         CLASS_FORMAT_ERROR,
340         UNSUPPORTED_CLASS_VERSION_ERROR,
341         EXCEPTION_IN_INITIALIZER_ERROR,
342         INCOMPATIBLE_CLASS_CHANGE_ERROR,
343         ABSTRACT_METHOD_ERROR,
344         ILLEGAL_ACCESS_ERROR,
345         INSTANTIATION_ERROR,
346         NO_SUCH_FIELD_ERROR,
347         NO_SUCH_METHOD_ERROR,
348         NO_CLASS_DEF_FOUND_ERROR,
349         UNSATISFIED_LINK_ERROR,
350         VERIFY_ERROR,
351         THREAD_DEATH,
352         VIRTUAL_MACHINE_ERROR,
353         INTERNAL_ERROR,
354         OUT_OF_MEMORY_ERROR,
355         STACK_OVERFLOW_ERROR,
356         UNKNOWN_ERROR,
357         AWT_ERROR,
358         UNDECLARED_THROWABLE_EXCEPTION,
359         UNSUPPORTED_LOOK_AND_FEEL_EXCEPTION,
360     }));
361     ALL_TEST_THROWABLES = Collections.unmodifiableSet(temp);
362
363     temp = new ExceptionHashSet();
364     temp.add(AnySubType.v(Scene.v().getRefType("java.lang.Throwable")));
365     ALL_THROWABLES_REP = Collections.unmodifiableSet(temp);
366     }
367
368
369     /**
370      * Verifies that the argument <code>set</code> is catchable as
371      * any of the exceptions in <code>members</code>.
372      *
373      * @param set <code>ThrowableSet</code> whose membership is
374      * being checked.
375      *
376      * @param members A {@link List} of {@link RefType} objects representing
377      * Throwable classes.
378      *
379      */

380     public boolean catchableAsAllOf(ThrowableSet set, List members) {
381     boolean result = true;
382     for (Iterator i = members.iterator(); i.hasNext(); ) {
383         RefType member = (RefType) i.next();
384         result = result && set.catchableAs(member);
385     }
386     return result;
387     }
388          
389     
390     /**
391      * Verifies that the argument <code>set</code> is not catchable as
392      * any of the exceptions in <code>members</code>.
393      *
394      * @param set <code>ThrowableSet</code> whose membership is
395      * being checked.
396      *
397      * @param members A {@link List} of {@link RefType} objects representing
398      * Throwable classes.
399      *
400      */

401     public boolean catchableAsNoneOf(ThrowableSet set, List members) {
402     boolean result = true;
403     for (Iterator i = members.iterator(); i.hasNext(); ) {
404         RefType member = (RefType) i.next();
405         result = result && (! set.catchableAs(member));
406     }
407     return result;
408     }
409          
410     
411     /**
412      * Verifies that the argument <code>set</code> is catchable as
413      * any of the exceptions in <code>members</code>, but not
414      * as any other of the exceptions ALL_TEST_THROWABLES.
415      *
416      * @param set <code>ThrowableSet</code> whose membership is
417      * being checked.
418      *
419      * @param members A {@link List} of {@link RefType} objects representing
420      * Throwable classes.
421      *
422      */

423     public boolean catchableOnlyAs(ThrowableSet set, List members) {
424     boolean result = true;
425     for (Iterator i = members.iterator(); i.hasNext(); ) {
426         RefType member = (RefType) i.next();
427         result = result && (set.catchableAs(member));
428     }
429     for (Iterator i = ALL_TEST_THROWABLES.iterator(); i.hasNext(); ) {
430         RefType e = (RefType) i.next();
431         if (! members.contains(e)) {
432         result = result && (! set.catchableAs(e));
433         }
434     }
435     return result;
436     }
437          
438
439     /**
440      * Returns a Set representation of the subset of ALL_TEST_THROWABLES
441      * which are catchable by the argument <code>ThrowableSet</code>
442      * (for use in assertions about the catchable exceptions.
443      *
444      * @param thrownSet <code>ThrowableSet</code> representing some
445      * set of possible exceptions.
446      */

447     public Set catchableSubset(ThrowableSet thrownSet)
448     {
449     Set result = new ExceptionHashSet(ALL_TEST_THROWABLES.size());
450     for (Iterator i = ALL_TEST_THROWABLES.iterator(); i.hasNext(); ) {
451         RefType e = (RefType) i.next();
452         if (thrownSet.catchableAs(e)) {
453         result.add(e);
454         }
455     }
456     return result;
457     }
458
459
460     /**
461      * Checks that the internal representation of the exceptions
462      * in an argument {@link ThrowableSet} matches expectations.
463      *
464      * @param thrownSet {@link ThrowableSet} whose contents are being
465      * checked.
466      *
467      * @param expectedIncludes contains the collection of {@link
468      * RefType} and {@link AnySubType} objects that are expected to be
469      * included in <code>thrownSet</code>.
470      *
471      * @param expectedExcludes contains the collection of {@link
472      * RefType} and {@link AnySubType} objects that are expected to be
473      * excluded from <code>thrownSet</code>.
474      *
475      * @return <code>true</code> if <code>thrownSet</code> and
476      * <code>expected</code> have the same members.
477      */

478     public static boolean sameMembers(Set expectedIncluded, Set expectedExcluded,
479                       ThrowableSet thrownSet) {
480     if ( (expectedIncluded.size() != thrownSet.typesIncluded().size())
481         || (expectedExcluded.size() != thrownSet.typesExcluded().size())
482         || (! expectedIncluded.containsAll(thrownSet.typesIncluded()))
483         || (! expectedExcluded.containsAll(thrownSet.typesExcluded()))) {
484         System.out.println("\nExpected included:" + expectedIncluded.toString()
485                    + "\nExpected excluded:" + expectedExcluded.toString()
486                    + "\nActual:\n" + thrownSet.toString());
487         return false;
488     } else {
489         return true;
490     }
491     }
492
493
494     public static class ExceptionHashSet extends HashSet {
495     // The only difference between this and a standard HashSet is that
496
// we override the toString() method to make ExceptionHashSets
497
// easier to compare when they appear in JUnit assertion failure
498
// messages.
499

500     ExceptionHashSet() {
501         super();
502     }
503
504     ExceptionHashSet(Collection c) {
505         super(c);
506     }
507
508     ExceptionHashSet(int initialCapacity) {
509         super(initialCapacity);
510     }
511
512     public String JavaDoc toString() {
513         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
514         Object JavaDoc[] contents = (Object JavaDoc[]) this.toArray();
515         Comparator comparator = new Comparator() {
516         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
517             // The order doesn't matter, so long as it is consistent.
518
return o1.toString().compareTo(o2.toString());
519         }
520         };
521         Arrays.sort(contents, comparator);
522         result.append("\nExceptionHashSet<");
523         for (int i = 0; i < contents.length; i++) {
524         result.append("\n\t");
525         result.append(contents[i].toString());
526         result.append("<");
527         result.append(Integer.toHexString(contents[i].hashCode()));
528         result.append(">");
529         }
530         result.append("\n>ExceptionHashSet");
531         return result.toString();
532     }
533     }
534 }
535
Popular Tags