-
Bug
-
Resolution: Fixed
-
P4
-
2.0, 1.0.2, 1.1, 1.1.1
-
beta
-
generic, sparc
-
solaris_2.5, solaris_2.5.1
-
Verified
allan.jacobs@Eng 1997-03-31
In the code my21.java below, the abstract class Y21 does not allow
inheritance from the two interfaces I1 and I2. These interfaces both
declare an abstract method f() returning an int value. The two
methods have throws clauses that are not identical (though they are
not incompatible). Oddly, if the order of the interfaces in the
implements clause of the class declaration is reversed, then javac
allows the construction. This is done in the source code
my12.java.
algol% cat my21.java
interface I1 {
public abstract int f() throws RuntimeException;
}
interface I2 {
public abstract int f() throws Throwable;
}
// Note the order of implementation of I1 & I2
abstract class Y21 implements I2,I1 {}
class Z21 extends Y21 {
public int f() throws RuntimeException {
RuntimeException e = new RuntimeException();
throw e;
}
}
class X {
public static void main(String[] arg)
{
Z21 z21 = new Z21();
}
}
algol% javac my21.java
my21.java:6: Invalid exception class java.lang.Throwable in throws clause. The exception must be a subclass of an exception thrown by int f() from interface I1.
public abstract int f() throws Throwable;
^
1 error
algol% cat my12.java
interface I1 {
public abstract int f() throws RuntimeException;
}
interface I2 {
public abstract int f() throws Throwable;
}
// Note the order of implementation of I1 & I2
abstract class Y12 implements I1,I2 {}
class Z12 extends Y12 {
public int f() throws RuntimeException {
RuntimeException e = new RuntimeException();
throw e;
}
}
class X {
public static void main(String[] arg)
{
Z12 z12 = new Z12();
}
}
algol% javac my12.java
algol%
- duplicates
-
JDK-4022782 javac reports throws clause errors in a code that has none.
- Closed
-
JDK-4022901 compile-time error for inherited abstract methods with throws conflict
- Closed
- relates to
-
JDK-4514502 javap generates NullPointerException for the compiled code.
- Closed