Skip to content

Commit 51932fe

Browse files
Inline private field ProxyInputStream.exceptionHandler (#780)
* chore: inline `ProxyInputStream.exceptionHandler` field The private, final field `exceptionHandler` was always set to `Erase::rethrow` and had no way to be changed (no setter provided). By inlining its single usage, `handleIOException` becomes simpler and its behavior is clearly fixed, with changes only possible through subclassing. * Inline private constant field ProxyInputStream.exceptionHandler #780 --------- Co-authored-by: Gary Gregory <[email protected]>
1 parent 28873d1 commit 51932fe

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ The <action> type attribute can be add,update,fix,remove.
6060
<!-- UPDATE -->
6161
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 87 #774.</action>
6262
<action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump commons-codec:commons-codec from 1.18.0 to 1.19.0.</action>
63-
<action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump commons.bytebuddy.version from 1.17.6 to 1.17.7 #769.</action>
63+
<action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump commons.bytebuddy.version from 1.17.6 to 1.17.7 #769.</action>
64+
<!-- REMOVE -->
65+
<action type="remove" dev="pkarwasz" due-to="Piotr P. Karwasz">Inline private constant field ProxyInputStream.exceptionHandler #780.</action>
6466
</release>
6567
<release version="2.20.0" date="2025-07-13" description="Version 2.20.0: Java 8 or later is required.">
6668
<!-- FIX -->

src/main/java/org/apache/commons/io/input/ProxyInputStream.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import org.apache.commons.io.IOUtils;
2626
import org.apache.commons.io.build.AbstractStreamBuilder;
27-
import org.apache.commons.io.function.Erase;
28-
import org.apache.commons.io.function.IOConsumer;
2927
import org.apache.commons.io.function.IOIntConsumer;
3028

3129
/**
@@ -102,11 +100,6 @@ public B setAfterRead(final IOIntConsumer afterRead) {
102100
*/
103101
private volatile boolean closed;
104102

105-
/**
106-
* Handles exceptions.
107-
*/
108-
private final IOConsumer<IOException> exceptionHandler;
109-
110103
private final IOIntConsumer afterRead;
111104

112105
/**
@@ -130,7 +123,6 @@ protected ProxyInputStream(final AbstractBuilder<?, ?> builder) throws IOExcepti
130123
public ProxyInputStream(final InputStream proxy) {
131124
// the delegate is stored in a protected superclass variable named 'in'.
132125
super(proxy);
133-
this.exceptionHandler = Erase::rethrow;
134126
this.afterRead = IOIntConsumer.NOOP;
135127
}
136128

@@ -144,7 +136,6 @@ public ProxyInputStream(final InputStream proxy) {
144136
protected ProxyInputStream(final InputStream proxy, final AbstractBuilder<?, ?> builder) {
145137
// the delegate is stored in a protected superclass instance variable named 'in'.
146138
super(proxy);
147-
this.exceptionHandler = Erase::rethrow;
148139
this.afterRead = builder.getAfterRead() != null ? builder.getAfterRead() : IOIntConsumer.NOOP;
149140
}
150141

@@ -245,7 +236,7 @@ public void close() throws IOException {
245236
* @since 2.0
246237
*/
247238
protected void handleIOException(final IOException e) throws IOException {
248-
exceptionHandler.accept(e);
239+
throw e;
249240
}
250241

251242
/**

0 commit comments

Comments
 (0)