Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

LanceAndersen
Copy link
Contributor

@LanceAndersen LanceAndersen commented Apr 14, 2023

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8305945: (zipfs) Opening a directory to get input stream produces incorrect exception message

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

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 14, 2023

👋 Welcome back lancea! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 14, 2023
@openjdk
Copy link

openjdk bot commented Apr 14, 2023

@LanceAndersen The following labels will be automatically applied to this pull request:

  • core-libs
  • nio

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.

@openjdk openjdk bot added nio nio-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Apr 14, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 14, 2023

Webrevs

Copy link
Member

@naotoj naotoj left a 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

Copy link
Member

@sormuras sormuras left a 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.

@openjdk
Copy link

openjdk bot commented Apr 14, 2023

@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:

8305945: (zipfs) Opening a directory to get input stream produces incorrect exception message

Reviewed-by: naoto, cstein

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 master branch:

  • caa841d: 8306029: ProblemList runtime/ErrorHandling/TestDwarf.java on linux
  • 314bad3: 8305935: Resolve multiple definition of 'jmm_<interface|version>' when statically linking with JDK native libraries
  • 793da60: 8305403: Shenandoah evacuation workers may deadlock
  • 2cc4bf1: 8305085: Suppress removal warning for finalize() from test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineFinalizer.java
  • 5a78865: 8304930: Enable Link Time Optimization as an option for Visual C++
  • 30a140b: 8304912: Use OperatingSystem enum in java.desktop module
  • 1fd4006: 8305405: Compile_lock not needed in Universe::genesis()
  • ebeee6d: 8305404: Compile_lock not needed for InstanceKlass::implementor()
  • d2ce04b: 8301496: Replace NULL with nullptr in cpu/riscv
  • 54bf370: 8170945: Collectors$Partition should override more Map methods
  • ... and 199 more: https://git.openjdk.org/jdk/compare/7239150f8aff0e3dc07c5b27f6b7fb07237bfc55...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 14, 2023
@LanceAndersen
Copy link
Contributor Author

Looks good, Lance. Nit: copyright year -> 2023

Geez, working in too many workspaces. Thank you, just pushed the update

@LanceAndersen
Copy link
Contributor Author

Looks good to me.

Thank you Christian

Copy link
Contributor

@eirbjo eirbjo left a 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";
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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());
Copy link
Contributor

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
        }

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

@LanceAndersen
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 20, 2023

Going to push as commit c6a288d.
Since your change was applied there have been 276 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 20, 2023
@openjdk openjdk bot closed this Apr 20, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 20, 2023
@openjdk
Copy link

openjdk bot commented Apr 20, 2023

@LanceAndersen Pushed as commit c6a288d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated nio nio-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

5 participants