-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u20
-
x86_64
-
linux
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
A DESCRIPTION OF THE PROBLEM :
When compiling the following class:
public class ThrowableParameters {
public static void main(String[] args) {
Collections.singletonList(Arrays.asList("a", "b", "c").stream()
.findAny()
.orElseThrow(() -> new IllegalArgumentException("?")));
}
}
the compiler reports an error like this:
src/test/bugs/ThrowableParameters.java:10: error: unreported exception X; must be caught or declared to be thrown
.orElseThrow(() -> new IllegalArgumentException("?")));
^
where X,T are type-variables:
X extends Throwable declared in method <X>orElseThrow(Supplier<? extends X>)
T extends Object declared in class Optional
1 error
This does not happen if the outer invocation of Collections.singletonList() is removed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile without errors.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test.bugs;
import java.util.Arrays;
import java.util.Collections;
public class ThrowableParameters {
public static void main(String[] args) {
Collections.singletonList(Arrays.asList("a", "b", "c").stream()
.findAny()
.orElseThrow(() -> new IllegalArgumentException("?")));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The parameter to Collections.singletonList() can be first assigned to a local variable.
The orElseThrow() method can have explicit type parameters added, like this:
.<IllegalArgumentException> orElseThrow(() -> new IllegalArgumentException("?")));
In both cases the class compiles without errors.
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
A DESCRIPTION OF THE PROBLEM :
When compiling the following class:
public class ThrowableParameters {
public static void main(String[] args) {
Collections.singletonList(Arrays.asList("a", "b", "c").stream()
.findAny()
.orElseThrow(() -> new IllegalArgumentException("?")));
}
}
the compiler reports an error like this:
src/test/bugs/ThrowableParameters.java:10: error: unreported exception X; must be caught or declared to be thrown
.orElseThrow(() -> new IllegalArgumentException("?")));
^
where X,T are type-variables:
X extends Throwable declared in method <X>orElseThrow(Supplier<? extends X>)
T extends Object declared in class Optional
1 error
This does not happen if the outer invocation of Collections.singletonList() is removed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile without errors.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test.bugs;
import java.util.Arrays;
import java.util.Collections;
public class ThrowableParameters {
public static void main(String[] args) {
Collections.singletonList(Arrays.asList("a", "b", "c").stream()
.findAny()
.orElseThrow(() -> new IllegalArgumentException("?")));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The parameter to Collections.singletonList() can be first assigned to a local variable.
The orElseThrow() method can have explicit type parameters added, like this:
.<IllegalArgumentException> orElseThrow(() -> new IllegalArgumentException("?")));
In both cases the class compiles without errors.
- backport of
-
JDK-8165147 Issue with type inference of generic exceptions in mapped optional
- Closed
- duplicates
-
JDK-8054569 problem with type inference of generic exceptions
- Closed