-
Notifications
You must be signed in to change notification settings - Fork 6.3k
8367067: Improve exception handling in HttpRequest.BodyPublishers #26876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d1c01e6
Introduce `CheckedItera{ble,tor}` to avoid wrapping `IOE`s
vy 53f483b
Simplify `iterable`-vs-`throwable` check
vy a68707c
Improve wording on nullability
vy 89dba9a
Revert redundant changes
vy 6548445
Introduce `CheckedItera{ble,tor}` to avoid wrapping `IOE`s
vy 03b0469
Simplify `iterable`-vs-`throwable` check
vy 03f8f2a
Improve wording on nullability
vy a42731e
Revert redundant changes
vy 4bc3608
Harden exception handling in request publishers
vy e72b7f5
More tests and improvements
vy 6ab2a29
Merge branch 'sendAsyncEx2' into sendAsyncEx
vy 6dfd27b
Fix compilation errors
vy 3ae8622
Improve `FromPublisherTest`
vy 2757579
Minor improvements
vy fa1a736
Revert clean-up of redundant tests to keep PR focused
vy 2d0cc8d
Merge remote-tracking branch 'upstream/master' into sendAsyncEx
vy 75e98c4
Make `CheckedIterable` throw exceptions
vy 9fd8958
Revert `FilePublisherTest` and `FlowAdapterPublisherTest` changes
vy e9bc9e7
Remove IOE rethrows
vy 983c1e7
Fix `FileChannelPublisherTest` failures
vy 88ea9d4
Update copyright year of `PullPublisher`
vy 6e46e61
Use scratch directory for `OfFileTest::DEFAULT_FS_DIR`
vy 11a74dd
Close ZIP file system at exit
vy 74dddad
Merge remote-tracking branch 'upstream/master' into sendAsyncEx
vy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/java.net.http/share/classes/jdk/internal/net/http/CheckedIterable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package jdk.internal.net.http; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* An {@link Iterable} clone for {@link CheckedIterator}. | ||
* | ||
* @param <E> the type of elements returned by the produced iterators | ||
*/ | ||
@FunctionalInterface | ||
interface CheckedIterable<E> { | ||
|
||
/** | ||
* {@return an {@linkplain CheckedIterator iterator} over elements of type {@code E}} | ||
*/ | ||
CheckedIterator<E> iterator(); | ||
|
||
static <E> CheckedIterable<E> fromIterable(Iterable<E> iterable) { | ||
return () -> { | ||
Iterator<E> iterator = iterable.iterator(); | ||
return CheckedIterator.fromIterator(iterator); | ||
}; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/java.net.http/share/classes/jdk/internal/net/http/CheckedIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package jdk.internal.net.http; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* An {@link java.util.Iterator} clone supporting checked exceptions. | ||
* | ||
* @param <E> the type of elements returned by this iterator | ||
*/ | ||
interface CheckedIterator<E> { | ||
|
||
/** | ||
* {@return {@code true} if the iteration has more elements} | ||
* @throws Exception if operation fails | ||
*/ | ||
boolean hasNext() throws Exception; | ||
|
||
/** | ||
* {@return the next element in the iteration} | ||
* | ||
* @throws NoSuchElementException if the iteration has no more elements | ||
* @throws Exception if operation fails | ||
*/ | ||
E next() throws Exception; | ||
|
||
static <E> CheckedIterator<E> fromIterator(Iterator<E> iterator) { | ||
return new CheckedIterator<>() { | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return iterator.hasNext(); | ||
} | ||
|
||
@Override | ||
public E next() { | ||
return iterator.next(); | ||
} | ||
|
||
}; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.