You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/21 15:06:23 UTC

[commons-io] branch master updated: [IO-705] MarkShieldInputStream#reset should throw UnsupportedOperationException.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new b4d80a8  [IO-705] MarkShieldInputStream#reset should throw UnsupportedOperationException.
b4d80a8 is described below

commit b4d80a81558da0dc75cc2a93e629686b88c738cb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 21 10:06:18 2021 -0500

    [IO-705] MarkShieldInputStream#reset should throw
    UnsupportedOperationException.
---
 src/changes/changes.xml                                               | 3 +++
 src/main/java/org/apache/commons/io/input/MarkShieldInputStream.java  | 2 +-
 .../org/apache/commons/io/input/UnsupportedOperationExceptions.java   | 2 +-
 .../java/org/apache/commons/io/input/MarkShieldInputStreamTest.java   | 4 ++--
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dc43325..589d011 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action issue="IO-690" dev="ggregory" type="fix" due-to="Chris Heisterkamp, Gary Gregory">
         IOUtils.toByteArray(null) no longer throws a NullPointerException.
       </action>
+      <action issue="IO-705" dev="ggregory" type="fix" due-to="Hao Zhong, Gary Gregory">
+        MarkShieldInputStream#reset should throw UnsupportedOperationException.
+      </action>
       <!-- ADD -->
       <action dev="ggregory" type="add" due-to="Gary Gregory">
         Add FileSystemProviders class.
diff --git a/src/main/java/org/apache/commons/io/input/MarkShieldInputStream.java b/src/main/java/org/apache/commons/io/input/MarkShieldInputStream.java
index cb025a3..b8725bd 100644
--- a/src/main/java/org/apache/commons/io/input/MarkShieldInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/MarkShieldInputStream.java
@@ -59,6 +59,6 @@ public class MarkShieldInputStream extends ProxyInputStream {
     @SuppressWarnings("sync-override")
     @Override
     public void reset() throws IOException {
-        throw new IOException("mark/reset not supported");
+        throw UnsupportedOperationExceptions.reset();
     }
 }
diff --git a/src/main/java/org/apache/commons/io/input/UnsupportedOperationExceptions.java b/src/main/java/org/apache/commons/io/input/UnsupportedOperationExceptions.java
index acc213d..3b92200 100644
--- a/src/main/java/org/apache/commons/io/input/UnsupportedOperationExceptions.java
+++ b/src/main/java/org/apache/commons/io/input/UnsupportedOperationExceptions.java
@@ -20,7 +20,7 @@ package org.apache.commons.io.input;
 /**
  * Package-private factory for {@link UnsupportedOperationException} to provide messages with consistent formatting.
  *
- * TODO Consider making this public and use from LineIterator.
+ * TODO Consider making this public and use from LineIterator but this feels like it belongs in LANG rather than IO.
  */
 class UnsupportedOperationExceptions {
 
diff --git a/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java b/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java
index 55a0b16..1c3e4a0 100644
--- a/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/MarkShieldInputStreamTest.java
@@ -78,7 +78,7 @@ public class MarkShieldInputStreamTest {
         // test wrapping an underlying stream which does NOT support marking
         try (final MarkShieldInputStream msis = new MarkShieldInputStream(
                 new NullInputStream(64, false, false))) {
-            assertThrows(IOException.class, () -> msis.reset());
+            assertThrows(UnsupportedOperationException.class, () -> msis.reset());
         }
     }
 
@@ -87,7 +87,7 @@ public class MarkShieldInputStreamTest {
         // test wrapping an underlying stream which supports marking
         try (final MarkShieldInputStream msis = new MarkShieldInputStream(
                 new NullInputStream(64, true, false))) {
-            assertThrows(IOException.class, () -> msis.reset());
+            assertThrows(UnsupportedOperationException.class, () -> msis.reset());
         }
     }