ppkarwasz commented on code in PR #789:
URL: https://github.com/apache/commons-io/pull/789#discussion_r2390212588


##########
src/test/java/org/apache/commons/io/build/AbstractOriginTest.java:
##########
@@ -133,50 +117,57 @@ private boolean isValid(final RandomAccessFile raf) 
throws IOException {
 
     protected abstract B newOriginRw() throws IOException;
 
-    protected void resetOriginRw() throws IOException {
-        // No-op
-    }
-
-    protected void setOriginRo(final AbstractOrigin<T, B> origin) {
-        this.originRo = origin;
-    }
-
-    protected void setOriginRw(final AbstractOrigin<T, B> origin) {
-        this.originRw = origin;
-    }
-
     @Test
     void testGetByteArray() throws IOException {
-        assertArrayEquals(getFixtureByteArray(), getOriginRo().getByteArray());
+        final AbstractOrigin<T, B> originRo = newOriginRo();
+        assertArrayEquals(getFixtureByteArray(), originRo.getByteArray());
+        assertOpen(originRo);
+        close(originRo);
     }
 
     @Test
     void testGetByteArrayAt_0_0() throws IOException {
-        assertArrayEquals(new byte[] {}, getOriginRo().getByteArray(0, 0));
+        final AbstractOrigin<T, B> originRo = newOriginRo();
+        assertArrayEquals(new byte[]{}, originRo.getByteArray(0, 0));
+        assertOpen(originRo);
+        close(originRo);

Review Comment:
   My main motivation was to prevent `toByteArray()` implementations of this 
kind:
   
   ```java
   IOUtils.toByteArray(getInputStream());
   ```
   This would be clearly wrong, if `getInputStream()` creates a **new** input 
stream (instead of a wrapper).
   
   However, I see now that I went into the wrong direction and the proposed 
changes would never detect that.
   
   What would work is to move `originRo` to a temporary path, which would cause 
a test failure on Windows if the test leaves any unclosed `RandomAccessFile` or 
`FileInputStream`, because this prevents the removal of the temporary 
directory. An unclosed stream opened with `Files.getInputStream()` (which we 
currently use) doesn't prevent the removal of the parent directory even on 
Windows.
   
   I am closing this PR. Thanks for sparring with me.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to