1 /*******************************************************************************
2  * Copyright (c) 2003, 2016 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *     Jesper Steen Moller - bug 404146 nested try-catch-finally-blocks leads to unrunnable Java byte code
14  *******************************************************************************/
15 package org.eclipse.jdt.core.tests.compiler.regression;
16 
17 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18 
19 import junit.framework.Test;
20 @SuppressWarnings({ "rawtypes" })
21 public class TryStatement17Test extends AbstractRegressionTest {
22 
23 static {
24 //	TESTS_NAMES = new String[] { "test061" };
25 //	TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 };
26 //	TESTS_RANGE = new int[] { 11, -1 };
27 }
TryStatement17Test(String name)28 public TryStatement17Test(String name) {
29 	super(name);
30 }
suite()31 public static Test suite() {
32 	return buildMinimalComplianceTestSuite(testClass(), F_1_7);
33 }
test001()34 public void test001() {
35 	this.runNegativeTest(
36 		new String[] {
37 			"X.java",
38 			"import java.io.*;\n" +
39 			"\n" +
40 			"public class X {\n" +
41 			"	public static void main(String[] args) {\n" +
42 			"		try {\n" +
43 			"			System.out.println();\n" +
44 			"			Reader r = new FileReader(args[0]);\n" +
45 			"			r.read();\n" +
46 			"		} catch(IOException | FileNotFoundException e) {\n" +
47 			"			e.printStackTrace();\n" +
48 			"		}\n" +
49 			"	}\n" +
50 			"}",
51 		},
52 		"----------\n" +
53 		"1. ERROR in X.java (at line 9)\n" +
54 		"	} catch(IOException | FileNotFoundException e) {\n" +
55 		"	                      ^^^^^^^^^^^^^^^^^^^^^\n" +
56 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
57 		"----------\n");
58 }
test002()59 public void test002() {
60 	this.runNegativeTest(
61 		new String[] {
62 			"X.java",
63 			"import java.io.*;\n" +
64 			"\n" +
65 			"public class X {\n" +
66 			"	public static void main(String[] args) {\n" +
67 			"		try {\n" +
68 			"			System.out.println();\n" +
69 			"			Reader r = new FileReader(args[0]);\n" +
70 			"			r.read();\n" +
71 			"		} catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" +
72 			"			e.printStackTrace();\n" +
73 			"		}\n" +
74 			"	}\n" +
75 			"}",
76 		},
77 		"----------\n" +
78 		"1. ERROR in X.java (at line 9)\n" +
79 		"	} catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" +
80 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
81 		"The exception FileNotFoundException is already caught by the alternative FileNotFoundException\n" +
82 		"----------\n" +
83 		"2. ERROR in X.java (at line 9)\n" +
84 		"	} catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" +
85 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
86 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
87 		"----------\n" +
88 		"3. ERROR in X.java (at line 9)\n" +
89 		"	} catch(FileNotFoundException | FileNotFoundException | IOException e) {\n" +
90 		"	                                ^^^^^^^^^^^^^^^^^^^^^\n" +
91 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
92 		"----------\n");
93 }
test003()94 public void test003() {
95 	this.runNegativeTest(
96 		new String[] {
97 			"X.java",
98 			"import java.io.*;\n" +
99 			"\n" +
100 			"public class X {\n" +
101 			"	public static void main(String[] args) {\n" +
102 			"		try {\n" +
103 			"			System.out.println();\n" +
104 			"			Reader r = new FileReader(args[0]);\n" +
105 			"			r.read();\n" +
106 			"		} catch(FileNotFoundException e) {" +
107 			"			e.printStackTrace();\n" +
108 			"		} catch(FileNotFoundException | IOException e) {\n" +
109 			"			e.printStackTrace();\n" +
110 			"		}\n" +
111 			"	}\n" +
112 			"}",
113 		},
114 		"----------\n" +
115 		"1. ERROR in X.java (at line 10)\n" +
116 		"	} catch(FileNotFoundException | IOException e) {\n" +
117 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
118 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
119 		"----------\n");
120 }
test004()121 public void test004() {
122 	this.runNegativeTest(
123 		new String[] {
124 			"X.java",
125 			"import java.io.*;\n" +
126 			"\n" +
127 			"public class X {\n" +
128 			"	public static void main(String[] args) {\n" +
129 			"		try {\n" +
130 			"			System.out.println();\n" +
131 			"			Reader r = new FileReader(args[0]);\n" +
132 			"			r.read();\n" +
133 			"		} catch(RuntimeException | Exception e) {" +
134 			"			e.printStackTrace();\n" +
135 			"		} catch(FileNotFoundException | IOException e) {\n" +
136 			"			e.printStackTrace();\n" +
137 			"		}\n" +
138 			"	}\n" +
139 			"}",
140 		},
141 		"----------\n" +
142 		"1. ERROR in X.java (at line 9)\n" +
143 		"	} catch(RuntimeException | Exception e) {			e.printStackTrace();\n" +
144 		"	        ^^^^^^^^^^^^^^^^\n" +
145 		"The exception RuntimeException is already caught by the alternative Exception\n" +
146 		"----------\n" +
147 		"2. ERROR in X.java (at line 10)\n" +
148 		"	} catch(FileNotFoundException | IOException e) {\n" +
149 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
150 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
151 		"----------\n");
152 }
test005()153 public void test005() {
154 	this.runNegativeTest(
155 		new String[] {
156 			"X.java",
157 			"import java.io.*;\n" +
158 			"\n" +
159 			"public class X {\n" +
160 			"	public static void main(String[] args) {\n" +
161 			"		try {\n" +
162 			"			System.out.println();\n" +
163 			"			Reader r = new FileReader(\"Zork\");\n" +
164 			"			r.read();\n" +
165 			"		} catch(NumberFormatException | RuntimeException e) {\n" +
166 			"			e.printStackTrace();\n" +
167 			"		} catch(FileNotFoundException | IOException e) {\n" +
168 			"			// ignore\n" +
169 			"		}\n" +
170 			"	}\n" +
171 			"}",
172 		},
173 		"----------\n" +
174 		"1. ERROR in X.java (at line 9)\n" +
175 		"	} catch(NumberFormatException | RuntimeException e) {\n" +
176 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
177 		"The exception NumberFormatException is already caught by the alternative RuntimeException\n" +
178 		"----------\n" +
179 		"2. ERROR in X.java (at line 11)\n" +
180 		"	} catch(FileNotFoundException | IOException e) {\n" +
181 		"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
182 		"The exception FileNotFoundException is already caught by the alternative IOException\n" +
183 		"----------\n");
184 }
185 //Test that lub is not used for checking for checking the exceptions
test006()186 public void test006() {
187 	this.runNegativeTest(
188 		new String[] {
189 			"X.java",
190 
191 			"public class X {\n" +
192 			"	public static void main(String[] args) {\n" +
193 			"		try {\n" +
194 			"			throw new Foo();\n"+
195 			"		} catch(SonOfFoo | DaughterOfFoo e) {\n" +
196 			"			e.printStackTrace();\n" +
197 			"		}\n" +
198 			"	}\n" +
199 			"}\n" +
200 			"class Foo extends Exception {}\n"+
201 			"class SonOfFoo extends Foo {}\n"+
202 			"class DaughterOfFoo extends Foo {}\n"
203 		},
204 		"----------\n" +
205 		"1. ERROR in X.java (at line 4)\n" +
206 		"	throw new Foo();\n" +
207 		"	^^^^^^^^^^^^^^^^\n" +
208 		"Unhandled exception type Foo\n" +
209 		"----------\n" +
210 		"2. WARNING in X.java (at line 10)\n" +
211 		"	class Foo extends Exception {}\n" +
212 		"	      ^^^\n" +
213 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
214 		"----------\n" +
215 		"3. WARNING in X.java (at line 11)\n" +
216 		"	class SonOfFoo extends Foo {}\n" +
217 		"	      ^^^^^^^^\n" +
218 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
219 		"----------\n" +
220 		"4. WARNING in X.java (at line 12)\n" +
221 		"	class DaughterOfFoo extends Foo {}\n" +
222 		"	      ^^^^^^^^^^^^^\n" +
223 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
224 		"----------\n");
225 }
test007()226 public void test007() {
227 	this.runConformTest(
228 		new String[] {
229 			"X.java",
230 
231 			"public class X {\n" +
232 			"	public static void main(String[] args) {\n" +
233 			"		try {\n" +
234 			"			throw new Foo();\n"+
235 			"		} catch(SonOfFoo | DaughterOfFoo e) {\n" +
236 			"			System.out.println(\"Caught lub\");\n" +
237 			"		} catch(Foo e) {\n" +
238 			"           System.out.println(\"Caught Foo\");\n" +
239 			"        }\n" +
240 			"	}\n" +
241 			"}\n" +
242 			"class Foo extends Exception {}\n"+
243 			"class SonOfFoo extends Foo {}\n"+
244 			"class DaughterOfFoo extends Foo {}\n"
245 		},
246 		"Caught Foo");
247 }
248 // test that lub is not used for precise rethrow
test008()249 public void test008() {
250 	this.runNegativeTest(
251 		new String[] {
252 			"X.java",
253 			"public class X {\n" +
254 			"	public static void main(String[] args) {\n" +
255 			"		try {\n" +
256 			"			if (args.length == 0) throw new SonOfFoo();\n"+
257 			"			throw new DaughterOfFoo();\n" +
258 			"		} catch(SonOfFoo | DaughterOfFoo e) {\n" +
259 			"			try {\n" +
260 			"				throw e;\n" +
261 			"			} catch(SonOfFoo | DaughterOfFoo e1) {}\n"+
262 			"		}\n" +
263 			"	}\n" +
264 			"}\n" +
265 			"class Foo extends Exception {}\n"+
266 			"class SonOfFoo extends Foo {}\n"+
267 			"class DaughterOfFoo extends Foo {}\n"
268 		},
269 		"----------\n" +
270 		"1. WARNING in X.java (at line 13)\n" +
271 		"	class Foo extends Exception {}\n" +
272 		"	      ^^^\n" +
273 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
274 		"----------\n" +
275 		"2. WARNING in X.java (at line 14)\n" +
276 		"	class SonOfFoo extends Foo {}\n" +
277 		"	      ^^^^^^^^\n" +
278 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
279 		"----------\n" +
280 		"3. WARNING in X.java (at line 15)\n" +
281 		"	class DaughterOfFoo extends Foo {}\n" +
282 		"	      ^^^^^^^^^^^^^\n" +
283 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
284 		"----------\n");
285 }
test009()286 public void test009() {
287 	this.runNegativeTest(
288 		new String[] {
289 			"X.java",
290 			"import java.io.*;\n" +
291 			"\n" +
292 			"public class X {\n" +
293 			"	public static void main(String[] args) {\n" +
294 			"		try {\n" +
295 			"			throw new IOException();\n" +
296 			"		} catch(IOException | RuntimeException e) {\n" +
297 			"			e = new IOException();\n" +
298 			"		}\n" +
299 			"	}\n" +
300 			"}",
301 		},
302 		"----------\n" +
303 		"1. ERROR in X.java (at line 8)\n" +
304 		"	e = new IOException();\n" +
305 		"	^\n" +
306 		"The parameter e of a multi-catch block cannot be assigned\n" +
307 		"----------\n");
308 }
309 //Test that union type checks are done for a precise throw too
test010()310 public void test010() {
311 	this.runNegativeTest(
312 		new String[] {
313 			"X.java",
314 
315 			"public class X {\n" +
316 			"	public static void main(String[] args) {\n" +
317 			"		try {\n" +
318 			"			throw new DaughterOfFoo();\n"+
319 			"		} catch(SonOfFoo | DaughterOfFoo e) {\n" +
320 			"			e.printStackTrace();\n" +
321 			"		}\n" +
322 			"	}\n" +
323 			"}\n" +
324 			"class Foo extends Exception {}\n"+
325 			"class SonOfFoo extends Foo {}\n"+
326 			"class DaughterOfFoo extends Foo {}\n"
327 		},
328 		"----------\n" +
329 		"1. ERROR in X.java (at line 5)\n" +
330 		"	} catch(SonOfFoo | DaughterOfFoo e) {\n" +
331 		"	        ^^^^^^^^\n" +
332 		"Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" +
333 		"----------\n" +
334 		"2. WARNING in X.java (at line 10)\n" +
335 		"	class Foo extends Exception {}\n" +
336 		"	      ^^^\n" +
337 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
338 		"----------\n" +
339 		"3. WARNING in X.java (at line 11)\n" +
340 		"	class SonOfFoo extends Foo {}\n" +
341 		"	      ^^^^^^^^\n" +
342 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
343 		"----------\n" +
344 		"4. WARNING in X.java (at line 12)\n" +
345 		"	class DaughterOfFoo extends Foo {}\n" +
346 		"	      ^^^^^^^^^^^^^\n" +
347 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
348 		"----------\n");
349 }
350 // Test that a rethrow is precisely computed
test011()351 public void test011() {
352 	this.runNegativeTest(
353 		new String[] {
354 			"X.java",
355 			"public class X {\n" +
356 			"	public static void main(String[] args) {\n" +
357 			"		try {\n" +
358 			"			throw new DaughterOfFoo();\n"+
359 			"		} catch(Foo e) {\n" +
360 			"			try {\n" +
361 			"				throw e;\n" +
362 			"			} catch (SonOfFoo e1) {\n" +
363 			"			 	e1.printStackTrace();\n" +
364 			"			} catch (Foo e1) {}\n" +
365 			"		}\n" +
366 			"	}\n" +
367 			"}\n"+
368 			"class Foo extends Exception {}\n"+
369 			"class SonOfFoo extends Foo {}\n"+
370 			"class DaughterOfFoo extends Foo {}\n"
371 		},
372 		"----------\n" +
373 		"1. ERROR in X.java (at line 8)\n" +
374 		"	} catch (SonOfFoo e1) {\n" +
375 		"	         ^^^^^^^^\n" +
376 		"Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" +
377 		"----------\n" +
378 		"2. WARNING in X.java (at line 14)\n" +
379 		"	class Foo extends Exception {}\n" +
380 		"	      ^^^\n" +
381 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
382 		"----------\n" +
383 		"3. WARNING in X.java (at line 15)\n" +
384 		"	class SonOfFoo extends Foo {}\n" +
385 		"	      ^^^^^^^^\n" +
386 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
387 		"----------\n" +
388 		"4. WARNING in X.java (at line 16)\n" +
389 		"	class DaughterOfFoo extends Foo {}\n" +
390 		"	      ^^^^^^^^^^^^^\n" +
391 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
392 		"----------\n");
393 }
394 //Test that a rethrow is precisely computed
test012()395 public void test012() {
396 	this.runNegativeTest(
397 		new String[] {
398 			"X.java",
399 			"public class X {\n" +
400 			"	public static void main(String[] args) {\n" +
401 			"		try {\n" +
402 			"			throw new DaughterOfFoo();\n"+
403 			"		} catch(Foo e) {\n" +
404 			"			try {\n" +
405 			"				throw e;\n" +
406 			"			} catch (SonOfFoo e1) {\n" +
407 			"			 	e1.printStackTrace();\n" +
408 			"			} catch (Foo e1) {}\n" +
409 			"			finally {" +
410 			"				System.out.println(\"\");}\n" +
411 			"		}\n" +
412 			"	}\n" +
413 			"}\n"+
414 			"class Foo extends Exception {}\n"+
415 			"class SonOfFoo extends Foo {}\n"+
416 			"class DaughterOfFoo extends Foo {}\n"
417 		},
418 		"----------\n" +
419 		"1. ERROR in X.java (at line 8)\n" +
420 		"	} catch (SonOfFoo e1) {\n" +
421 		"	         ^^^^^^^^\n" +
422 		"Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" +
423 		"----------\n" +
424 		"2. WARNING in X.java (at line 15)\n" +
425 		"	class Foo extends Exception {}\n" +
426 		"	      ^^^\n" +
427 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
428 		"----------\n" +
429 		"3. WARNING in X.java (at line 16)\n" +
430 		"	class SonOfFoo extends Foo {}\n" +
431 		"	      ^^^^^^^^\n" +
432 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
433 		"----------\n" +
434 		"4. WARNING in X.java (at line 17)\n" +
435 		"	class DaughterOfFoo extends Foo {}\n" +
436 		"	      ^^^^^^^^^^^^^\n" +
437 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
438 		"----------\n");
439 }
440 // Test that if the rethrow argument is modified (not effectively final), then it is not precisely
441 // computed
test013()442 public void test013() {
443 	this.runNegativeTest(
444 		new String[] {
445 			"X.java",
446 			"public class X {\n" +
447 			"	public static void main(String[] args) {\n" +
448 			"		try {\n" +
449 			"			throw new DaughterOfFoo();\n"+
450 			"		} catch(Foo e) {\n" +
451 			"			try {\n" +
452 			"				e = new Foo();\n" +
453 			"				throw e;\n" +
454 			"			} catch (SonOfFoo e1) {\n" +
455 			"			 	e1.printStackTrace();\n" +
456 			"			} catch (Foo e1) {}\n"+
457 			"		}\n" +
458 			"	}\n" +
459 			"}\n"+
460 			"class Foo extends Exception {}\n"+
461 			"class SonOfFoo extends Foo {}\n"+
462 			"class DaughterOfFoo extends Foo {}\n"
463 		},
464 		"----------\n" +
465 		"1. WARNING in X.java (at line 15)\n" +
466 		"	class Foo extends Exception {}\n" +
467 		"	      ^^^\n" +
468 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
469 		"----------\n" +
470 		"2. WARNING in X.java (at line 16)\n" +
471 		"	class SonOfFoo extends Foo {}\n" +
472 		"	      ^^^^^^^^\n" +
473 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
474 		"----------\n" +
475 		"3. WARNING in X.java (at line 17)\n" +
476 		"	class DaughterOfFoo extends Foo {}\n" +
477 		"	      ^^^^^^^^^^^^^\n" +
478 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
479 		"----------\n");
480 }
481 
482 // Test that if the rethrow argument is modified in a different flow (not effectively final), then also precise throw
483 // should not be computed
test014()484 public void test014() {
485 	this.runNegativeTest(
486 		new String[] {
487 			"X.java",
488 			"public class X {\n" +
489 			"	public static void main(String[] args) {\n" +
490 			"		try {\n" +
491 			"			throw new DaughterOfFoo();\n"+
492 			"		} catch(Foo e) {\n" +
493 			"			try {\n" +
494 			"				boolean DEBUG = true;\n" +
495 			"				if (DEBUG) {\n" +
496 			"					throw e;\n"+
497 			"				}" +
498 			"				e = new Foo();\n" +
499 			"				e.printStackTrace();\n"+
500 			"			} catch (SonOfFoo e1) {\n" +
501 			"			 	e1.printStackTrace();\n" +
502 			"			} catch (Foo e1) {}\n"+
503 			"		}\n" +
504 			"	}\n" +
505 			"}\n"+
506 			"class Foo extends Exception {}\n"+
507 			"class SonOfFoo extends Foo {}\n"+
508 			"class DaughterOfFoo extends Foo {}\n"
509 		},
510 		"----------\n" +
511 		"1. WARNING in X.java (at line 18)\n" +
512 		"	class Foo extends Exception {}\n" +
513 		"	      ^^^\n" +
514 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
515 		"----------\n" +
516 		"2. WARNING in X.java (at line 19)\n" +
517 		"	class SonOfFoo extends Foo {}\n" +
518 		"	      ^^^^^^^^\n" +
519 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
520 		"----------\n" +
521 		"3. WARNING in X.java (at line 20)\n" +
522 		"	class DaughterOfFoo extends Foo {}\n" +
523 		"	      ^^^^^^^^^^^^^\n" +
524 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
525 		"----------\n");
526 }
527 
528 // test015 moved into org.eclipse.jdt.core.tests.compiler.regression.TryStatementTest.test070()
529 
530 // Test precise rethrow works good even in nested try catch block
test016()531 public void test016() {
532 	this.runNegativeTest(
533 		new String[] {
534 			"X.java",
535 			"public class X {\n" +
536 			"	public static void main(String[] args) {\n" +
537 			"		try {\n" +
538 			"			throw new DaughterOfFoo();\n"+
539 			"		} catch(Foo e) {\n" +
540 			"			try {\n" +
541 			"				throw new Foo();\n" +
542 			"			} catch (Foo e1) {\n" +
543 			"				try {\n" +
544 			"					throw e;\n" +
545 			"				} catch (SonOfFoo e2) {\n" +
546 			"			 		e1.printStackTrace();\n" +
547 			"				} catch (Foo e3) {}\n" +
548 			"			}\n" +
549 			"		}\n" +
550 			"	}\n" +
551 			"}\n"+
552 			"class Foo extends Exception {}\n"+
553 			"class SonOfFoo extends Foo {}\n"+
554 			"class DaughterOfFoo extends Foo {}\n"
555 		},
556 		"----------\n" +
557 		"1. ERROR in X.java (at line 11)\n" +
558 		"	} catch (SonOfFoo e2) {\n" +
559 		"	         ^^^^^^^^\n" +
560 		"Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" +
561 		"----------\n" +
562 		"2. WARNING in X.java (at line 18)\n" +
563 		"	class Foo extends Exception {}\n" +
564 		"	      ^^^\n" +
565 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
566 		"----------\n" +
567 		"3. WARNING in X.java (at line 19)\n" +
568 		"	class SonOfFoo extends Foo {}\n" +
569 		"	      ^^^^^^^^\n" +
570 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
571 		"----------\n" +
572 		"4. WARNING in X.java (at line 20)\n" +
573 		"	class DaughterOfFoo extends Foo {}\n" +
574 		"	      ^^^^^^^^^^^^^\n" +
575 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
576 		"----------\n");
577 }
578 // Test lub computation.
test017()579 public void test017() {
580 	this.runNegativeTest(
581 		new String[] {
582 			"X.java",
583 			"public class X {\n" +
584 			"    public static void main(String [] args) {\n" +
585 			"        doSomething(false);\n" +
586 			"    }\n" +
587 			"    public static void doSomething (boolean bool) {\n" +
588 			"        try {\n" +
589 			"            if (bool)\n" +
590 			"                throw new GrandSonOfFoo();\n" +
591 			"            else \n" +
592 			"                throw new GrandDaughterOfFoo();\n" +
593 			"        } catch(SonOfFoo | DaughterOfFoo e) {\n" +
594 			"        	SonOfFoo s = e;\n" +
595 			"        	e.callableOnBothGenders();\n" +
596 			"        	e.callableOnlyOnMales();\n" +
597 			"        	e.callableOnlyOnFemales();\n" +
598 			"        }\n" +
599 			"    }\n" +
600 			"}\n" +
601 			"class Foo extends Exception {\n" +
602 			"	void callableOnBothGenders () {\n" +
603 			"	}\n" +
604 			"}\n" +
605 			"class SonOfFoo extends Foo {\n" +
606 			"	void callableOnlyOnMales() {\n" +
607 			"	}\n" +
608 			"}\n" +
609 			"class GrandSonOfFoo extends SonOfFoo {}\n" +
610 			"class DaughterOfFoo extends Foo {\n" +
611 			"	void callableOnlyOnFemales() {\n" +
612 			"	}\n" +
613 			"}\n" +
614 			"class GrandDaughterOfFoo extends DaughterOfFoo {}\n"
615 		},
616 		"----------\n" +
617 		"1. ERROR in X.java (at line 12)\n" +
618 		"	SonOfFoo s = e;\n" +
619 		"	             ^\n" +
620 		"Type mismatch: cannot convert from Foo to SonOfFoo\n" +
621 		"----------\n" +
622 		"2. ERROR in X.java (at line 14)\n" +
623 		"	e.callableOnlyOnMales();\n" +
624 		"	  ^^^^^^^^^^^^^^^^^^^\n" +
625 		"The method callableOnlyOnMales() is undefined for the type Foo\n" +
626 		"----------\n" +
627 		"3. ERROR in X.java (at line 15)\n" +
628 		"	e.callableOnlyOnFemales();\n" +
629 		"	  ^^^^^^^^^^^^^^^^^^^^^\n" +
630 		"The method callableOnlyOnFemales() is undefined for the type Foo\n" +
631 		"----------\n" +
632 		"4. WARNING in X.java (at line 19)\n" +
633 		"	class Foo extends Exception {\n" +
634 		"	      ^^^\n" +
635 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
636 		"----------\n" +
637 		"5. WARNING in X.java (at line 23)\n" +
638 		"	class SonOfFoo extends Foo {\n" +
639 		"	      ^^^^^^^^\n" +
640 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
641 		"----------\n" +
642 		"6. WARNING in X.java (at line 27)\n" +
643 		"	class GrandSonOfFoo extends SonOfFoo {}\n" +
644 		"	      ^^^^^^^^^^^^^\n" +
645 		"The serializable class GrandSonOfFoo does not declare a static final serialVersionUID field of type long\n" +
646 		"----------\n" +
647 		"7. WARNING in X.java (at line 28)\n" +
648 		"	class DaughterOfFoo extends Foo {\n" +
649 		"	      ^^^^^^^^^^^^^\n" +
650 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
651 		"----------\n" +
652 		"8. WARNING in X.java (at line 32)\n" +
653 		"	class GrandDaughterOfFoo extends DaughterOfFoo {}\n" +
654 		"	      ^^^^^^^^^^^^^^^^^^\n" +
655 		"The serializable class GrandDaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
656 		"----------\n");
657 }
658 // Test explicit final modifiers
test018()659 public void test018() {
660 	this.runNegativeTest(
661 		new String[] {
662 			"X.java",
663 			"public class X {\n" +
664 			"	public static void foo(boolean bool) throws Foo {\n" +
665 			"		try {\n" +
666 			"			if (bool) \n" +
667 			"			    throw new DaughterOfFoo();\n" +
668 			"			else\n" +
669 			"			    throw new SonOfFoo();\n" +
670 			"		} catch (final SonOfFoo | DaughterOfFoo e){\n" +
671 			"			throw e;\n" +
672 			"		}\n" +
673 			"	}\n" +
674 			"	public static void main(String[] args) {\n" +
675 			"		try {\n" +
676 			"			foo(true);\n" +
677 			"		} catch(Foo e) {} \n" +
678 			"	}\n" +
679 			"}\n" +
680 			"class Foo extends Exception {}\n" +
681 			"class SonOfFoo extends Foo {}\n" +
682 			"class DaughterOfFoo extends Foo {}\n"
683 		},
684 		"----------\n" +
685 		"1. WARNING in X.java (at line 7)\n" +
686 		"	throw new SonOfFoo();\n" +
687 		"	^^^^^^^^^^^^^^^^^^^^^\n" +
688 		"Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" +
689 		"----------\n" +
690 		"2. WARNING in X.java (at line 18)\n" +
691 		"	class Foo extends Exception {}\n" +
692 		"	      ^^^\n" +
693 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
694 		"----------\n" +
695 		"3. WARNING in X.java (at line 19)\n" +
696 		"	class SonOfFoo extends Foo {}\n" +
697 		"	      ^^^^^^^^\n" +
698 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
699 		"----------\n" +
700 		"4. WARNING in X.java (at line 20)\n" +
701 		"	class DaughterOfFoo extends Foo {}\n" +
702 		"	      ^^^^^^^^^^^^^\n" +
703 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
704 		"----------\n");
705 }
706 // Test explicit final modifiers
test019()707 public void test019() {
708 	this.runNegativeTest(
709 		new String[] {
710 			"X.java",
711 			"public class X {\n" +
712 			"	public static void foo(boolean bool) throws Foo {\n" +
713 			"		try {\n" +
714 			"			if (bool) \n" +
715 			"			    throw new DaughterOfFoo();\n" +
716 			"			else\n" +
717 			"			    throw new SonOfFoo();\n" +
718 			"		} catch (final SonOfFoo | final DaughterOfFoo e){\n" +
719 			"			throw e;\n" +
720 			"		}\n" +
721 			"	}\n" +
722 			"	public static void main(String[] args) {\n" +
723 			"		try {\n" +
724 			"			foo(true);\n" +
725 			"		} catch(Foo e) {} \n" +
726 			"	}\n" +
727 			"}\n" +
728 			"class Foo extends Exception {}\n" +
729 			"class SonOfFoo extends Foo {}\n" +
730 			"class DaughterOfFoo extends Foo {}\n"
731 		},
732 		"----------\n" +
733 		"1. ERROR in X.java (at line 8)\n" +
734 		"	} catch (final SonOfFoo | final DaughterOfFoo e){\n" +
735 		"	                          ^^^^^\n" +
736 		"Syntax error on token \"final\", delete this token\n" +
737 		"----------\n" +
738 		"2. WARNING in X.java (at line 18)\n" +
739 		"	class Foo extends Exception {}\n" +
740 		"	      ^^^\n" +
741 		"The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
742 		"----------\n" +
743 		"3. WARNING in X.java (at line 19)\n" +
744 		"	class SonOfFoo extends Foo {}\n" +
745 		"	      ^^^^^^^^\n" +
746 		"The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
747 		"----------\n" +
748 		"4. WARNING in X.java (at line 20)\n" +
749 		"	class DaughterOfFoo extends Foo {}\n" +
750 		"	      ^^^^^^^^^^^^^\n" +
751 		"The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
752 		"----------\n");
753 }
754 // Test that for unchecked exceptions, we don't do any precise analysis.
test020()755 public void test020() {
756 	this.runConformTest(
757 		new String[] {
758 			"X.java",
759 			"public class X {\n" +
760 					"	public static void main(String [] args)  {\n" +
761 					"		try {\n" +
762 					"		} catch (NullPointerException s) {\n" +
763 					"			try {\n" +
764 					"				throw s;\n" +
765 					"			} catch (ArithmeticException e) {\n" +
766 					"			}\n" +
767 					"		} finally {\n" +
768 					"			System.out.println(\"All done\");\n" +
769 					"		}\n" +
770 					"	}\n" +
771 					"}\n"
772 		},
773 		"All done");
774 }
775 // Test multicatch behavior.
test021()776 public void test021() {
777 	this.runConformTest(
778 		new String[] {
779 			"X.java",
780 			"public class X {\n" +
781 			"	public static void main(String[] args) {\n" +
782 			"		String[] exceptions = { \"NullPointerException\", \"ArithmeticException\",\n" +
783 			"				\"ArrayStoreException\", \"ArrayIndexOutOfBoundsException\" };\n" +
784 			"\n" +
785 			"		for (String exception : exceptions) {\n" +
786 			"			try {\n" +
787 			"				switch (exception) {\n" +
788 			"				case \"NullPointerException\":\n" +
789 			"					throw new NullPointerException();\n" +
790 			"				case \"ArithmeticException\":\n" +
791 			"					throw new ArithmeticException();\n" +
792 			"				case \"ArrayStoreException\":\n" +
793 			"					throw new ArrayStoreException();\n" +
794 			"				case \"ArrayIndexOutOfBoundsException\":\n" +
795 			"					throw new ArrayIndexOutOfBoundsException();\n" +
796 			"				}\n" +
797 			"			} catch (NullPointerException | ArithmeticException | ArrayStoreException | ArrayIndexOutOfBoundsException e) {\n" +
798 			"				System.out.println(e);\n" +
799 			"			}\n" +
800 			"		}\n" +
801 			"	}\n" +
802 			"}\n"
803 		},
804 		"java.lang.NullPointerException\n" +
805 		"java.lang.ArithmeticException\n" +
806 		"java.lang.ArrayStoreException\n" +
807 		"java.lang.ArrayIndexOutOfBoundsException");
808 }
test022()809 public void test022() {
810 	this.runNegativeTest(
811 			new String[] {
812 				"X.java",
813 				"public class X<T extends Exception> {\n" +
814 				"public void foo(boolean bool) throws Exception {\n" +
815 				"	try {\n" +
816 	            "	if (bool)\n" +
817 	            "		throw new Exception();\n" +
818 	            "	else\n" +
819 	            "		throw new NullPointerException();\n" +
820 	        	"	} catch (T | NullPointerException e) {}\n" +
821 	        	"}\n" +
822 	        	"}\n"},
823 	        	"----------\n" +
824     			"1. ERROR in X.java (at line 8)\n" +
825     			"	} catch (T | NullPointerException e) {}\n" +
826     			"	         ^\n" +
827     			"Cannot use the type parameter T in a catch block\n" +
828     			"----------\n"
829 			);
830 }
test023()831 public void test023() {
832 	this.runNegativeTest(
833 			new String[] {
834 				"X.java",
835 				"public class X<T> extends Exception {\n" +
836 				"public void foo(boolean bool) throws Exception {\n" +
837 				"	try {\n" +
838 	            "	if (bool)\n" +
839 	            "		throw new Exception();\n" +
840 	            "	else\n" +
841 	            "		throw new NullPointerException();\n" +
842 	        	"	} catch (X<String> | NullPointerException e) {}\n" +
843 	        	"}\n" +
844 	        	"}\n"},
845 	        	"----------\n" +
846     			"1. WARNING in X.java (at line 1)\n" +
847     			"	public class X<T> extends Exception {\n" +
848     			"	             ^\n" +
849     			"The serializable class X does not declare a static final serialVersionUID field of type long\n" +
850     			"----------\n" +
851     			"2. ERROR in X.java (at line 1)\n" +
852     			"	public class X<T> extends Exception {\n" +
853     			"	                          ^^^^^^^^^\n" +
854     			"The generic class X<T> may not subclass java.lang.Throwable\n" +
855     			"----------\n" +
856     			"3. ERROR in X.java (at line 8)\n" +
857     			"	} catch (X<String> | NullPointerException e) {}\n" +
858     			"	         ^\n" +
859     			"Cannot use the parameterized type X<String> either in catch block or throws clause\n" +
860     			"----------\n"
861 			);
862 }
863 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=340486
test024()864 public void test024() {
865 	this.runNegativeTest(
866 			new String[] {
867 				"X.java",
868 				"import java.io.FileNotFoundException;\n" +
869 				"import java.io.IOException;\n" +
870 				"public class X {\n" +
871 				"    public static void main(String [] args) {\n" +
872 				"        try {\n" +
873 				"            if (args.length == 0)\n" +
874 				"                throw new FileNotFoundException();\n" +
875 				"            throw new IOException();\n" +
876 				"        } catch(IOException | FileNotFoundException e) {\n" +
877 				"        }\n" +
878 				"    }\n" +
879 				"}\n"
880 			},
881 			"----------\n" +
882 			"1. ERROR in X.java (at line 9)\n" +
883 			"	} catch(IOException | FileNotFoundException e) {\n" +
884 			"	                      ^^^^^^^^^^^^^^^^^^^^^\n" +
885 			"The exception FileNotFoundException is already caught by the alternative IOException\n" +
886 			"----------\n");
887 }
test024a()888 public void test024a() {
889 	this.runNegativeTest(
890 			new String[] {
891 				"X.java",
892 				"import java.io.FileNotFoundException;\n" +
893 				"import java.io.IOException;\n" +
894 				"public class X {\n" +
895 				"    public static void main(String [] args) {\n" +
896 				"        try {\n" +
897 				"            if (args.length == 0)\n" +
898 				"                throw new FileNotFoundException();\n" +
899 				"            throw new IOException();\n" +
900 				"        } catch(FileNotFoundException | IOException e) {\n" +
901 				"        }\n" +
902 				"    }\n" +
903 				"}\n"
904 			},
905 			"----------\n" +
906 			"1. ERROR in X.java (at line 9)\n" +
907 			"	} catch(FileNotFoundException | IOException e) {\n" +
908 			"	        ^^^^^^^^^^^^^^^^^^^^^\n" +
909 			"The exception FileNotFoundException is already caught by the alternative IOException\n" +
910 			"----------\n");
911 }
912 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=344824
test025()913 public void test025() {
914 	this.runNegativeTest(
915 			new String[] {
916 				"X.java",
917 				"public class X {\n" +
918 				"    public static void main(String[] args) {\n" +
919 				"        try {\n" +
920 				"            throw new D();\n" +
921 				"        } catch (F e) {\n" +
922 				"            try {\n" +
923 				"                throw e;\n" +
924 				"            } catch (F f) {\n" +
925 				"            } catch (RuntimeException | S f) {\n" +
926 				"            }\n" +
927 				"        }\n" +
928 				"    }\n" +
929 				"}\n" +
930 				"class F extends Exception {}\n" +
931 				"class S extends F {}\n" +
932 				"class D extends F {}\n"
933 			},
934 			"----------\n" +
935 			"1. ERROR in X.java (at line 9)\n" +
936 			"	} catch (RuntimeException | S f) {\n" +
937 			"	                            ^\n" +
938 			"Unreachable catch block for S. It is already handled by the catch block for F\n" +
939 			"----------\n" +
940 			"2. WARNING in X.java (at line 14)\n" +
941 			"	class F extends Exception {}\n" +
942 			"	      ^\n" +
943 			"The serializable class F does not declare a static final serialVersionUID field of type long\n" +
944 			"----------\n" +
945 			"3. WARNING in X.java (at line 15)\n" +
946 			"	class S extends F {}\n" +
947 			"	      ^\n" +
948 			"The serializable class S does not declare a static final serialVersionUID field of type long\n" +
949 			"----------\n" +
950 			"4. WARNING in X.java (at line 16)\n" +
951 			"	class D extends F {}\n" +
952 			"	      ^\n" +
953 			"The serializable class D does not declare a static final serialVersionUID field of type long\n" +
954 			"----------\n");
955 }
956 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=345522
test026()957 public void test026() {
958 	this.runNegativeTest(
959 			new String[] {
960 				"X.java",
961 				"import java.io.EOFException;\n" +
962 				"import java.io.FileNotFoundException;\n" +
963 				"public class X {\n" +
964 				"    X() { \n" +
965 				"        try {\n" +
966 				"            zoo();\n" +
967 				"        } catch (EOFException ea) {\n" +
968 				"        } catch (FileNotFoundException eb) {\n" +
969 				"        } catch (Exception ec) {\n" +
970 				"            throw ec;\n" +
971 				"        }\n" +
972 				"    }\n" +
973 				"    void zoo() throws FileNotFoundException, EOFException {\n" +
974 				"    }\n" +
975 				"}\n"
976 			},
977 			"");
978 }
979 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=345522
test026a()980 public void test026a() {
981 	this.runNegativeTest(
982 			new String[] {
983 				"X.java",
984 				"import java.io.EOFException;\n" +
985 				"import java.io.FileNotFoundException;\n" +
986 				"public class X {\n" +
987 				"    X() { \n" +
988 				"        try {\n" +
989 				"            zoo();\n" +
990 				"            throw new Exception();\n" +
991 				"        } catch (EOFException ea) {\n" +
992 				"        } catch (FileNotFoundException eb) {\n" +
993 				"        } catch (Exception ec) {\n" +
994 				"            throw ec;\n" +
995 				"        }\n" +
996 				"    }\n" +
997 				"    void zoo() throws FileNotFoundException, EOFException {\n" +
998 				"    }\n" +
999 				"}\n"
1000 			},
1001 			"----------\n" +
1002 			"1. ERROR in X.java (at line 11)\n" +
1003 			"	throw ec;\n" +
1004 			"	^^^^^^^^^\n" +
1005 			"Unhandled exception type Exception\n" +
1006 			"----------\n");
1007 }
1008 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=345579
test027()1009 public void test027() {
1010 	this.runConformTest(
1011 			new String[] {
1012 				"X.java",
1013 				"public class X {\n"+
1014 				"    X() throws Exception {\n"+
1015 				"        try {\n"+
1016 				"            throw (Throwable) new Exception();\n"+
1017 				"        } catch (Exception e) {\n"+
1018 				"            throw e;\n"+
1019 				"        } catch (Throwable e) {\n"+
1020 				"        }\n"+
1021 				"    }\n"+
1022 				"}\n"
1023 			},
1024 			"");
1025 }
1026 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=350361
test028()1027 public void test028() {
1028 	this.runConformTest(
1029 			new String[] {
1030 				"X.java",
1031 				"public class X {\n"+
1032 				"    public void foo () {\n"+
1033 				"        try {\n"+
1034 				"            throw new Exception(); \n"+
1035 				"        } catch (Exception e) {\n"+
1036 				"            if (e instanceof RuntimeException) \n" +
1037 				"            	throw (RuntimeException) e; \n"+
1038 				"        } \n"+
1039 				"    }\n"+
1040 				"}\n"
1041 			},
1042 			"");
1043 }
1044 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579
test029()1045 public void test029() { // with finally
1046 	this.runConformTest(
1047 			new String[] {
1048 				"X.java",
1049 				"public class X implements AutoCloseable {\n" +
1050 				"    public static void main(String[] args) {\n" +
1051 				"        try (X x = new X();) {\n" +
1052 				"        } catch (Exception x) {\n" +
1053 				"        } catch (Throwable y) {\n" +
1054 				"        } \n" +
1055 				"        finally {\n" +
1056 				"            System.out.println(\"Done\");\n" +
1057 				"        }\n" +
1058 				"    }\n" +
1059 				"    public void close() {\n" +
1060 				"    }\n" +
1061 				"}\n"
1062 			},
1063 			"Done");
1064 }
1065 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579
test030()1066 public void test030() { // no finally
1067 	this.runConformTest(
1068 			new String[] {
1069 				"X.java",
1070 				"public class X implements AutoCloseable {\n" +
1071 				"    public static void main(String[] args) {\n" +
1072 				"        try (X x = new X();) {\n" +
1073 				"        } catch (Exception x) {\n" +
1074 				"        } catch (Throwable y) {\n" +
1075 				"        } \n" +
1076 				"        System.out.println(\"Done\");\n" +
1077 				"    }\n" +
1078 				"    public void close() {\n" +
1079 				"    }\n" +
1080 				"}\n"
1081 			},
1082 			"Done");
1083 }
1084 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579
test031()1085 public void test031() { // with finally
1086 	this.runConformTest(
1087 			new String[] {
1088 				"X.java",
1089 				"public class X implements AutoCloseable {\n" +
1090 				"    public static void main(String [] args) throws XXException, YYException, ZZException {\n" +
1091 				"        try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
1092 				"        } catch (XException x) {\n" +
1093 				"        } catch (YException y) {\n" +
1094 				"        } catch (ZException z) {\n" +
1095 				"        } finally {\n" +
1096 				"            System.out.println(\"Done\");\n" +
1097 				"        }\n" +
1098 				"    }\n" +
1099 				"    public X() throws XException {\n" +
1100 				"        throw new XException();\n" +
1101 				"    }\n" +
1102 				"    public void close() throws XXException {\n" +
1103 				"        throw new XXException();\n" +
1104 				"    }\n" +
1105 				"}\n" +
1106 				"class Y implements AutoCloseable {\n" +
1107 				"    public Y() throws YException {\n" +
1108 				"        throw new YException();\n" +
1109 				"    }\n" +
1110 				"    public void close() throws YYException {\n" +
1111 				"        throw new YYException();\n" +
1112 				"    }\n" +
1113 				"}\n" +
1114 				"class Z implements AutoCloseable {\n" +
1115 				"    public Z() throws ZException {\n" +
1116 				"        throw new ZException();\n" +
1117 				"    }\n" +
1118 				"    public void close() throws ZZException {\n" +
1119 				"        throw new ZZException();\n" +
1120 				"    }\n" +
1121 				"}\n" +
1122 				"class XException extends Exception {}\n" +
1123 				"class XXException extends Exception {}\n" +
1124 				"class YException extends Exception {}\n" +
1125 				"class YYException extends Exception {}\n" +
1126 				"class ZException extends Exception {}\n" +
1127 				"class ZZException extends Exception {}\n"
1128 			},
1129 			"Done");
1130 }
1131 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350579
test032()1132 public void test032() { // no finally
1133 	this.runConformTest(
1134 			new String[] {
1135 				"X.java",
1136 				"public class X implements AutoCloseable {\n" +
1137 				"    public static void main(String [] args) throws XXException, YYException, ZZException {\n" +
1138 				"        try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
1139 				"        } catch (XException x) {\n" +
1140 				"        } catch (YException y) {\n" +
1141 				"        } catch (ZException z) {\n" +
1142 				"        }\n" +
1143 				"        System.out.println(\"Done\");\n" +
1144 				"    }\n" +
1145 				"    public X() throws XException {\n" +
1146 				"        throw new XException();\n" +
1147 				"    }\n" +
1148 				"    public void close() throws XXException {\n" +
1149 				"        throw new XXException();\n" +
1150 				"    }\n" +
1151 				"}\n" +
1152 				"class Y implements AutoCloseable {\n" +
1153 				"    public Y() throws YException {\n" +
1154 				"        throw new YException();\n" +
1155 				"    }\n" +
1156 				"    public void close() throws YYException {\n" +
1157 				"        throw new YYException();\n" +
1158 				"    }\n" +
1159 				"}\n" +
1160 				"class Z implements AutoCloseable {\n" +
1161 				"    public Z() throws ZException {\n" +
1162 				"        throw new ZException();\n" +
1163 				"    }\n" +
1164 				"    public void close() throws ZZException {\n" +
1165 				"        throw new ZZException();\n" +
1166 				"    }\n" +
1167 				"}\n" +
1168 				"class XException extends Exception {}\n" +
1169 				"class XXException extends Exception {}\n" +
1170 				"class YException extends Exception {}\n" +
1171 				"class YYException extends Exception {}\n" +
1172 				"class ZException extends Exception {}\n" +
1173 				"class ZZException extends Exception {}\n"
1174 			},
1175 			"Done");
1176 }
1177 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
testBug391092()1178 public void testBug391092() {
1179 	this.runNegativeTest(
1180 		new String[] {
1181 			"X.java",
1182 			"public class X {\n" +
1183 			"	public static void main(String [] args) {\n" +
1184 			"		try {\n" +
1185 			"		} catch (NullPointerException  | ArrayIndexOutOfBoundsException  e []) {\n" +
1186 			"		} catch (ClassCastException [] c) {\n" +
1187 			"		} catch (ArrayStoreException a[]) {\n" +
1188 			"		} catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" +
1189 			"		} catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
1190 			"		}\n" +
1191 			"    }\n" +
1192 			"}\n"
1193 		},
1194 		"----------\n" +
1195 		"1. ERROR in X.java (at line 4)\n" +
1196 		"	} catch (NullPointerException  | ArrayIndexOutOfBoundsException  e []) {\n" +
1197 		"	         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1198 		"Illegal attempt to create arrays of union types\n" +
1199 		"----------\n" +
1200 		"2. ERROR in X.java (at line 5)\n" +
1201 		"	} catch (ClassCastException [] c) {\n" +
1202 		"	         ^^^^^^^^^^^^^^^^^^^^^\n" +
1203 		"No exception of type ClassCastException[] can be thrown; an exception type must be a subclass of Throwable\n" +
1204 		"----------\n" +
1205 		"3. ERROR in X.java (at line 6)\n" +
1206 		"	} catch (ArrayStoreException a[]) {\n" +
1207 		"	         ^^^^^^^^^^^^^^^^^^^^^^^\n" +
1208 		"No exception of type ArrayStoreException[] can be thrown; an exception type must be a subclass of Throwable\n" +
1209 		"----------\n" +
1210 		"4. ERROR in X.java (at line 7)\n" +
1211 		"	} catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" +
1212 		"	         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1213 		"Illegal attempt to create arrays of union types\n" +
1214 		"----------\n" +
1215 		"5. ERROR in X.java (at line 8)\n" +
1216 		"	} catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
1217 		"	         ^^^^^^^^^^^^^^^^^^^^^^\n" +
1218 		"No exception of type ClassCastException[][] can be thrown; an exception type must be a subclass of Throwable\n" +
1219 		"----------\n" +
1220 		"6. ERROR in X.java (at line 8)\n" +
1221 		"	} catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" +
1222 		"	                                  ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1223 		"No exception of type ClassNotFoundException[] can be thrown; an exception type must be a subclass of Throwable\n" +
1224 		"----------\n");
1225 	}
1226 
1227 //Bug 404146 - nested try-catch-finally-blocks leads to unrunnable Java byte code
testBug404146()1228 public void testBug404146() {
1229 	runConformTest(
1230 		new String[] {
1231 			"X.java",
1232 			"import java.io.IOException;\n" +
1233 					"import javax.naming.NamingException;\n" +
1234 
1235 			"\n" +
1236 			"public final class X {\n" +
1237 			"\n" +
1238 			"    public static final void illegalStackMap() {\n" +
1239 			"        try {\n" +
1240 			"          try {\n" +
1241 			"            Y.decoy1();\n" +
1242 			"          } finally {\n" +
1243 			"            try {\n" +
1244 			"                Y.decoy2();\n" +
1245 			"            } catch (final IOException e) {\n" +
1246 			"              return;\n" +
1247 			"            }\n" +
1248 			"          }\n" +
1249 			"        } finally {\n" +
1250 			"          try {\n" +
1251 			"            Y.decoy3();\n" +
1252 			"          } catch (final NamingException e) {\n" +
1253 			"            return;\n" +
1254 			"          }\n" +
1255 			"        }\n" +
1256 			"    }\n" +
1257 			"}\n",
1258 			"Y.java",
1259 				"import java.io.IOException;\n" +
1260 						"import javax.naming.NamingException;\n" +
1261 			"public final class Y {\n" +
1262 			"\n" +
1263 			"    public static void decoy1() {}\n" +
1264 			"    public static void decoy2() throws IOException {}\n" +
1265 			"    public static void decoy3() throws NamingException {}\n" +
1266 			"}\n"
1267 		});
1268 }
testBug488569_001()1269 public void testBug488569_001() {
1270 	if (this.complianceLevel < ClassFileConstants.JDK9) {
1271 		this.runNegativeTest(
1272 			new String[] {
1273 					"X.java",
1274 					"public class X {\n" +
1275 					"    public static void main(String [] args) throws Exception {\n" +
1276 					"    	Z z1 = new Z();\n" +
1277 					"        try (Y y1 = new Y(); z1;) {\n" +
1278 					"        }  \n" +
1279 					"    }  \n" +
1280 					"}\n" +
1281 					"class Y implements AutoCloseable {\n" +
1282 					"	public void close() throws Exception {\n" +
1283 					"	}\n" +
1284 					"}\n" +
1285 					"\n" +
1286 					"class Z implements AutoCloseable {\n" +
1287 					"	public void close() throws Exception {\n" +
1288 					"	}   \n" +
1289 					"}\n" +
1290 					"\n"
1291 			},
1292 			"----------\n" +
1293 			"1. ERROR in X.java (at line 4)\n" +
1294 			"	try (Y y1 = new Y(); z1;) {\n" +
1295 			"	                     ^^\n" +
1296 			"Variable resource not allowed here for source level below 9\n" +
1297 			"----------\n");
1298 	} else {
1299 		this.runConformTest(
1300 			new String[] {
1301 				"X.java",
1302 				"public class X {\n" +
1303 				"    public static void main(String [] args) throws Exception {\n" +
1304 				"    	Z z1 = new Z();\n" +
1305 				"        try (Y y1 = new Y(); z1;) {\n" +
1306 				"        }  \n" +
1307 				"    }  \n" +
1308 				"}\n" +
1309 				"class Y implements AutoCloseable {\n" +
1310 				"	public void close() throws Exception {\n" +
1311 				"	}\n" +
1312 				"}\n" +
1313 				"\n" +
1314 				"class Z implements AutoCloseable {\n" +
1315 				"	public void close() throws Exception {\n" +
1316 				"	}   \n" +
1317 				"}\n" +
1318 				"\n"
1319 			},
1320 			"");
1321 
1322 	}
1323 }
1324 
testClass()1325 public static Class testClass() {
1326 	return TryStatement17Test.class;
1327 }
1328 }
1329