cnauroth commented on code in PR #7367:
URL: https://github.com/apache/hadoop/pull/7367#discussion_r1949680833


##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractOpenTest.java:
##########
@@ -408,4 +411,137 @@ public void testFloatingPointLength() throws Throwable {
         .isEqualTo(len);
   }
 
+  @Test
+  public void testInputStreamReadNullBuffer() throws Throwable {
+    // The JDK base InputStream (and by extension LocalFSFileInputStream) 
throws
+    // NullPointerException. Historically, DFSInputStream has thrown 
IllegalArgumentException
+    // instead. Allow either behavior.
+    describe("Attempting to read into a null buffer should throw 
IllegalArgumentException or " +
+        "NullPointerException");
+    Path path = methodPath();
+    FileSystem fs = getFileSystem();
+    int len = 4096;
+    createFile(fs, path, true,
+        dataset(len, 0x40, 0x80));
+    try (FSDataInputStream is = fs.openFile(path).build().get()) {
+      Assertions.assertThatThrownBy(() -> is.read(null, 0, 10))
+          .isInstanceOfAny(IllegalArgumentException.class, 
NullPointerException.class);

Review Comment:
   That's an interesting idea. I just tried going down the path of writing an 
`interceptAny` accepting a list of exception classes. The problem we run into 
though is that we want to parameterize on the exception type `E` and return the 
specific type. If the list can contain any exception type, then we can't put a 
meaningful bound on the returned `E`. It seems all we can do is devolve back to 
`Throwable`.
   
   I also don't currently have the use case (yet) of chaining additional 
analysis on that returned exception.
   
   I think I'll hold off on this.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to