-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8305945: (zipfs) Opening a directory to get input stream produces incorrect exception message #13482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back lancea! A progress list of the required criteria for merging this PR into |
@LanceAndersen The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, Lance. Nit: copyright year -> 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@LanceAndersen This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 209 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Geez, working in too many workspaces. Thank you, just pushed the update |
Thank you Christian |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Leaving some minor comments on the test.
/** | ||
* Zip file to create | ||
*/ | ||
public static final String ZIP_FILE = "directoryExceptionTest.zip"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ZIP_FILE could be a Path, to avoid Path.of(ZIP_FILE) wrapping later in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often do that but chose not to when I created the test but have updated per your suggestion
/** | ||
* @test | ||
* @bug 8305945 | ||
* @summary Validate that Zip FS provides the correct exception message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This summary could perhaps be a bit more specific about which condition / message it is testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
try (FileSystem zipfs = FileSystems.newFileSystem(ZIP_FILE)) { | ||
var file = zipfs.getPath(DIRECTORY_NAME); | ||
var x = assertThrows(FileSystemException.class, () -> Files.newInputStream(file)); | ||
assertEquals(x.getMessage(), DIR_EXCEPTION_MESSAGE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit asserts have the expected parameter first followed by the actual.
try (FileSystem zipfs = FileSystems.newFileSystem(ZIP_FILE)) { | ||
var file = zipfs.getPath(DIRECTORY_NAME); | ||
var x = assertThrows(FileSystemException.class, () -> Files.newInputStream(file)); | ||
assertEquals(DIR_EXCEPTION_MESSAGE, x.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, test doesn't need to depend the exception message. Checking FileSystemException::getOtherFile returns null would be a more robust way of checking that it didn't provide a second file by mistake, e.g.
try {
Files.newInputStream(DIRECTORY_NAME);
fail();
} catch (FileSystemException e) {
assertNull(e.getOtherFile());
} catch (IOException ioe) {
// allowed
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added validation for other file being null but also kept the existing validation of the message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, although I assume this test will fail if it throws a more general IOException (it's allowed to do that) or there is any adjustment to the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the unlikely event that either FileSystemException or the code below from zipfs is changed, then yes the error message could evolve
if (e.isDir())
throw new FileSystemException(getString(path), null, "is a directory");
I do not have a strong preference once way or the other and am happy to remove the message validation if that is what you prefer. I kept the validation as the original issue was surrounding the actual message being generated which aligns with the text included by zipfs when it threw the exception when obtaining the inputstream
I think it is worth mentioning that we have other tests that also validate exception messages(and we recently updated a couple zip tests because the message changed). So if we are going to move in the direction of not validating exception messages in tests, we should probably consider adding verbiage to the developers guide to provide that guidance and be consistent within the test suite
Let me know your preference and thank you for your thoughts as it is a useful discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you have is fine, I'm just making the point that the exception message is somewhat secondary, the important test is that if FileSystemException is thrown then its getOtherFile return should null as there is only one file in this operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you have is fine, I'm just making the point that the exception message is somewhat secondary
I guess this is also a question of testing the interface vs. testing the implementation.
To get good coverage of validation scenarios, I often find it quite useful to test on the actual message. This makes the test overspecific to the interface, but it helps make sure that each error condition is covered independently. Without asserting on the actual message, it can be hard to know if you are being shadowed by another higher level error condition. I've seen this a lot when adding test coverage for various ZIP processing code.
/integrate |
Going to push as commit c6a288d.
Your commit was automatically rebased without conflicts. |
@LanceAndersen Pushed as commit c6a288d. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this trivial change when ZipFS returns the wrong java.nio.file.FileSystemException message due the the parameters being reversed.
I also included a simple junit test as part of the fix.
Mach5 tiers1-3 are clean
Best
Lance
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13482/head:pull/13482
$ git checkout pull/13482
Update a local copy of the PR:
$ git checkout pull/13482
$ git pull https://git.openjdk.org/jdk.git pull/13482/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 13482
View PR using the GUI difftool:
$ git pr show -t 13482
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13482.diff
Webrev
Link to Webrev Comment