-
Bug
-
Resolution: Fixed
-
P3
-
9, 12
-
b16
-
Verified
A colleague reports:
OpenJDK 9's SocketInputStream.available() currently delegates to the impl even when eof is reached, even though in that case read() immediately returns -1 without delegating to the impl. This can lead to available() returning values other than 0 which is incorrect.
Here's a change that fixes SocketInputStream.available() to always return 0 in the case of eof, regardless of impl:
=== cut ===
diff -r 65464a307408 src/java.base/share/classes/java/net/SocketInputStream.java
--- a/src/java.base/share/classes/java/net/SocketInputStream.java Thu Aug 03 18:56:59 2017 +0000
+++ b/src/java.base/share/classes/java/net/SocketInputStream.java Fri Oct 06 17:03:43 2017 +0100
@@ -256,7 +256,11 @@
* @return the number of immediately available bytes
*/
public int available() throws IOException {
- return impl.available();
+ if (eof) {
+ return 0;
+ } else {
+ return impl.available();
+ }
}
/**
=== cut ===
OpenJDK 9's SocketInputStream.available() currently delegates to the impl even when eof is reached, even though in that case read() immediately returns -1 without delegating to the impl. This can lead to available() returning values other than 0 which is incorrect.
Here's a change that fixes SocketInputStream.available() to always return 0 in the case of eof, regardless of impl:
=== cut ===
diff -r 65464a307408 src/java.base/share/classes/java/net/SocketInputStream.java
--- a/src/java.base/share/classes/java/net/SocketInputStream.java Thu Aug 03 18:56:59 2017 +0000
+++ b/src/java.base/share/classes/java/net/SocketInputStream.java Fri Oct 06 17:03:43 2017 +0100
@@ -256,7 +256,11 @@
* @return the number of immediately available bytes
*/
public int available() throws IOException {
- return impl.available();
+ if (eof) {
+ return 0;
+ } else {
+ return impl.available();
+ }
}
/**
=== cut ===
- relates to
-
JDK-8212114 Reconsider the affect on closed streams resulting from 8189366
-
- Resolved
-