-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
23
-
Cause Known
-
generic
-
generic
-
Verified
ADDITIONAL SYSTEM INFORMATION :
Windows 11
WSL Linux (Ubuntu 20.04)
RHEL 8.8
All using Java 23 (currently build 26)
A DESCRIPTION OF THE PROBLEM :
In Java 23, java.util.concurrent.CancellationException exceptions are now getting wrapped in an additional CancellationException exception. This behavior has not been noted in the Java 23 release notes -> https://jdk.java.net/23/release-notes. Not sure if this change is intentional, but not posted or if it is unintentional.
In previous versions of Java (tested 22, 21 and 17), the extra exception wrapper was not added.
REGRESSION : Last worked in version 22.0.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a CompletableFuture and use the failedFuture method to add an exception, access the future via the getNow method and check the exception returned and compare the difference between Java 23 and previous Java versions. See submitted source code for an example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
From the attached program, in Java 22 and earlier, running "java Java23ExtraExceptionWrapper" yields:
java.util.concurrent.CancellationException: Testing cancellation
at Java23ExtraExceptionWrapper.<clinit>(Java23ExtraExceptionWrapper.java:5)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Provides a reason to cancel
... 1 more
ACTUAL -
In Java 23, it now returns the same exception, but now it is wrapped in an additional exception:
java.util.concurrent.CancellationException: getNow
at java.base/java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:454)
at java.base/java.util.concurrent.CompletableFuture.getNow(CompletableFuture.java:2178)
at Java23ExtraExceptionWrapper.main(Java23ExtraExceptionWrapper.java:13)
Caused by: java.util.concurrent.CancellationException: Testing cancellation
at Java23ExtraExceptionWrapper.<clinit>(Java23ExtraExceptionWrapper.java:5)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Provides a reason to cancel
... 1 more
---------- BEGIN SOURCE ----------
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
public class Java23ExtraExceptionWrapper {
private static final CancellationException CANCELLATION_X_CAUSED_BY_ARRAY_X =
(CancellationException) new CancellationException("Testing cancellation")
.initCause(new ArrayIndexOutOfBoundsException("Provides a reason to cancel"));
public static void main(String[] args) {
CompletableFuture<String> future = new CompletableFuture().failedFuture(CANCELLATION_X_CAUSED_BY_ARRAY_X);
try {
String result = future.getNow("result-if-not-done");
} catch (CancellationException x) {
x.printStackTrace();
}
}
}
---------- END SOURCE ----------
FREQUENCY : always
Windows 11
WSL Linux (Ubuntu 20.04)
RHEL 8.8
All using Java 23 (currently build 26)
A DESCRIPTION OF THE PROBLEM :
In Java 23, java.util.concurrent.CancellationException exceptions are now getting wrapped in an additional CancellationException exception. This behavior has not been noted in the Java 23 release notes -> https://jdk.java.net/23/release-notes. Not sure if this change is intentional, but not posted or if it is unintentional.
In previous versions of Java (tested 22, 21 and 17), the extra exception wrapper was not added.
REGRESSION : Last worked in version 22.0.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a CompletableFuture and use the failedFuture method to add an exception, access the future via the getNow method and check the exception returned and compare the difference between Java 23 and previous Java versions. See submitted source code for an example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
From the attached program, in Java 22 and earlier, running "java Java23ExtraExceptionWrapper" yields:
java.util.concurrent.CancellationException: Testing cancellation
at Java23ExtraExceptionWrapper.<clinit>(Java23ExtraExceptionWrapper.java:5)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Provides a reason to cancel
... 1 more
ACTUAL -
In Java 23, it now returns the same exception, but now it is wrapped in an additional exception:
java.util.concurrent.CancellationException: getNow
at java.base/java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:454)
at java.base/java.util.concurrent.CompletableFuture.getNow(CompletableFuture.java:2178)
at Java23ExtraExceptionWrapper.main(Java23ExtraExceptionWrapper.java:13)
Caused by: java.util.concurrent.CancellationException: Testing cancellation
at Java23ExtraExceptionWrapper.<clinit>(Java23ExtraExceptionWrapper.java:5)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Provides a reason to cancel
... 1 more
---------- BEGIN SOURCE ----------
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
public class Java23ExtraExceptionWrapper {
private static final CancellationException CANCELLATION_X_CAUSED_BY_ARRAY_X =
(CancellationException) new CancellationException("Testing cancellation")
.initCause(new ArrayIndexOutOfBoundsException("Provides a reason to cancel"));
public static void main(String[] args) {
CompletableFuture<String> future = new CompletableFuture().failedFuture(CANCELLATION_X_CAUSED_BY_ARRAY_X);
try {
String result = future.getNow("result-if-not-done");
} catch (CancellationException x) {
x.printStackTrace();
}
}
}
---------- END SOURCE ----------
FREQUENCY : always