mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
[ann] Exceptions with interfaces in multi-catch: assignability and control flow fix
This commit is contained in:
+42
-8
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
abstract class C {
|
||||
private static class NE { }
|
||||
private static class E extends Exception { public String s; }
|
||||
@@ -6,9 +21,9 @@ abstract class C {
|
||||
private static class E3 extends E { }
|
||||
private static class E4 extends E { }
|
||||
private static class RE extends RuntimeException { }
|
||||
private interface I<T> { }
|
||||
private static class IE1 extends E implements I<Integer> { }
|
||||
private static class IE2 extends E implements I<Long> { }
|
||||
private interface I<T> { void i(); }
|
||||
private static class IE1 extends E implements I<Integer> { public void i() { } }
|
||||
private static class IE2 extends E implements I<Long> { public void i() { } }
|
||||
private static class F<X> { F(X x) { } }
|
||||
|
||||
abstract void f() throws E1, E2;
|
||||
@@ -18,8 +33,7 @@ abstract class C {
|
||||
try { f(); } catch (E1 | E2 e) { }
|
||||
try { f(); } catch (E2 | E1 e) { e.printStackTrace(); System.out.println(e.s); }
|
||||
try { f(); } catch (E2 | E1 e) { } catch (E e) { } catch (RE e) { }
|
||||
try { f(); } catch (E1 | E2 e) { E ee = e; }
|
||||
try { g(); } catch (IE1 | IE2 e) { E ee = e; I ii = e; }
|
||||
try { g(); } catch (IE1 | IE2 e) { E ee = e; I ii = e; e.i(); }
|
||||
try { g(); } catch (IE1 | IE2 e) { F<?> f = new F<>(e); }
|
||||
try { g(); } catch (IE1 | IE2 e) { new F<I<? extends Number>>(e); }
|
||||
|
||||
@@ -33,12 +47,32 @@ abstract class C {
|
||||
try { f(); } catch (<error descr="Types in multi-catch must be disjoint: 'C.E' is a subclass of 'C.E'">E</error> | E ignore) { }
|
||||
|
||||
try { f(); } catch (E1 | E2 | <error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> e) { }
|
||||
try { f(); } catch (<error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> | <error descr="Exception 'C.E4' is never thrown in the corresponding try block">E4</error> | RE e) { }
|
||||
try { f(); } catch (<error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> | <error descr="Exception 'C.E4' is never thrown in the corresponding try block">E4</error> | RE e) { } catch (E e) { }
|
||||
try { <error descr="Unhandled exceptions: C.E1, C.E2">f();</error> } catch (E3 | E4 | RE e) { }
|
||||
|
||||
try { f(); } catch (E e) { } catch (<error descr="Exception 'C.E1' has already been caught">E1</error> | <error descr="Exception 'C.E3' has already been caught">E3</error> e) { }
|
||||
try { f(); } catch (E1 | E2 e) { } catch (<error descr="Exception 'C.E2' has already been caught">E2</error> e) { }
|
||||
|
||||
try { f(); } catch (E1 | E2 e) { } catch (E e) { <error descr="Incompatible types. Found: 'C.E', required: 'C.E1'">E1 ee = e;</error> }
|
||||
try { f(); } catch (E | RE e) { <error descr="Cannot assign a value to final variable 'e'">e = null</error>; }
|
||||
try { f(); } catch (E1 | E2 e) { <error descr="Incompatible types. Found: 'C.E1 | C.E2', required: 'C.E2'">E2 ee = e;</error> }
|
||||
try { f(); } catch (E1 | E2 e) { <error descr="Cannot assign a value to final variable 'e'">e = new E1()</error>; }
|
||||
try { f(); } catch (E1 | E2 e) { <error descr="Incompatible types. Found: 'C.E', required: 'C.E1 | C.E2'">e = new E()</error>; }
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
static class E extends Exception { }
|
||||
static interface I { void i(); }
|
||||
static class E1 extends E implements I { public void i() { } }
|
||||
static class E2 extends E implements I { public void i() { } }
|
||||
|
||||
void m(boolean f) {
|
||||
try {
|
||||
if (f)
|
||||
throw new E1();
|
||||
else
|
||||
throw new E2();
|
||||
} catch (E1|E2 e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user