-
Bug
-
Resolution: Fixed
-
P4
-
9
-
b120
-
Verified
There seems to be some problems with inference of exception -variables. Javac rejects it, though I don’t quite understand how and why:
class Main {
{
computeException(this::computeThrowable);
}
public <T, E extends Exception> void computeException(ThrowableComputable<T, E> c) throws E {}
public <E1 extends Throwable> Integer computeThrowable() throws E1 {
return 0;
}
public interface ThrowableComputable<T, E extends Throwable> {
T compute() throws E;
}
}
It looks like javac sees the following bounds
var T - upper bounds = java.lang.Object, lower bounds = java.lang.Integer, eq bounds = \n
var E - upper bounds = java.lang.Exception, lower bounds = E1, eq bounds = \n
var E1 - upper bounds = E,java.lang.Exception,java.lang.Throwable, lower bounds = , eq bounds = \n";
But I don’t understand why E1 participates in the computeException inference at all.
If I remove T from the code, e.g. would define:
public interface ThrowableComputable<T, E extends Throwable> {
Integer compute() throws E;
}
then javac would accept the code, E1 won’t be included.
With the initial sample, if I convert to lambda and extract variable
computeException(() -> {
Integer integer = computeThrowable();
return integer;
});
then code would also compile.
class Main {
{
computeException(this::computeThrowable);
}
public <T, E extends Exception> void computeException(ThrowableComputable<T, E> c) throws E {}
public <E1 extends Throwable> Integer computeThrowable() throws E1 {
return 0;
}
public interface ThrowableComputable<T, E extends Throwable> {
T compute() throws E;
}
}
It looks like javac sees the following bounds
var T - upper bounds = java.lang.Object, lower bounds = java.lang.Integer, eq bounds = \n
var E - upper bounds = java.lang.Exception, lower bounds = E1, eq bounds = \n
var E1 - upper bounds = E,java.lang.Exception,java.lang.Throwable, lower bounds = , eq bounds = \n";
But I don’t understand why E1 participates in the computeException inference at all.
If I remove T from the code, e.g. would define:
public interface ThrowableComputable<T, E extends Throwable> {
Integer compute() throws E;
}
then javac would accept the code, E1 won’t be included.
With the initial sample, if I convert to lambda and extract variable
computeException(() -> {
Integer integer = computeThrowable();
return integer;
});
then code would also compile.
- relates to
-
JDK-8168134 Inference: javac incorrectly propagating inner constraint with primitive target
-
- Closed
-
-
JDK-8164587 18.4: Ignore 'Serializable' upper bound for 'throws' ivars
-
- Closed
-