Skip to content

8293792: runtime/Dictionary/ProtectionDomainCacheTest.java fails with FileAlreadyExistsException: /tmp#10266

Closed
DamonFool wants to merge 1 commit intoopenjdk:masterfrom
DamonFool:JDK-8293792
Closed

8293792: runtime/Dictionary/ProtectionDomainCacheTest.java fails with FileAlreadyExistsException: /tmp#10266
DamonFool wants to merge 1 commit intoopenjdk:masterfrom
DamonFool:JDK-8293792

Conversation

@DamonFool
Copy link
Member

@DamonFool DamonFool commented Sep 14, 2022

Hi all,

runtime/Dictionary/ProtectionDomainCacheTest.java fails on Linux if /tmp is a symbolic link directory.
The root cause is that JarUtils.createJarFile [1] will throw FileAlreadyExistsException if parent is a symbolic directory.
So it seems better to test the existance of parent before creation.

Testing:

  • tier1~3 on Linux/x64 in progress, seems fine until now

Thanks.
Best regards,
Jie

[1] https://github.com/openjdk/jdk/blob/master/test/lib/jdk/test/lib/util/JarUtils.java#L72


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-8293792: runtime/Dictionary/ProtectionDomainCacheTest.java fails with FileAlreadyExistsException: /tmp

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10266/head:pull/10266
$ git checkout pull/10266

Update a local copy of the PR:
$ git checkout pull/10266
$ git pull https://git.openjdk.org/jdk pull/10266/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10266

View PR using the GUI difftool:
$ git pr show -t 10266

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10266.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 14, 2022

👋 Welcome back jiefu! 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 Sep 14, 2022
@openjdk
Copy link

openjdk bot commented Sep 14, 2022

@DamonFool The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 14, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 14, 2022

Webrevs

@jaikiran
Copy link
Member

Hello Jie,

The root cause is that JarUtils.createJarFile [1] will throw FileAlreadyExistsException if parent is a symbolic directory.

The JarUtils.createJarFile on that line uses:

// create the target directory
        Path parent = jarfile.getParent();
        if (parent != null) {
            Files.createDirectories(parent);
        }

From what I can see in the javadoc of java.nio.file.Files.createDirectories, it doesn't state that it will throw this exception in case of symbolic links (it actually doesn't talk about symbolic links). As per the API:

     * @throws  FileAlreadyExistsException
     *          if {@code dir} exists but is not a directory <i>(optional specific
     *          exception)</i>

So if it indeed is throwing a FileAlreadyExistsException then perhaps this API implementation needs a look at? I am not on a Linux system right now to test this, but would you be able to get the exact OS version and other details including the output of "ls -lh /tmp" to see what it is linked to?

@jaikiran
Copy link
Member

I could reproduce the issue with Files.createDirectories on a macos with a trivial program. It appears to be because of the use of NOFOLLOW_LINKS here https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/file/Files.java#L808. To me this appears to be something that either needs to be clarified in the the Files.createDirectories API or addressed/fixed there. I have asked for inputs on this from others who have more knowledge of this area.

@DamonFool
Copy link
Member Author

I could reproduce the issue with Files.createDirectories on a macos with a trivial program. It appears to be because of the use of NOFOLLOW_LINKS here https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/file/Files.java#L808. To me this appears to be something that either needs to be clarified in the the Files.createDirectories API or addressed/fixed there. I have asked for inputs on this from others who have more knowledge of this area.

Okay, thanks @jaikiran .

@coleenp
Copy link
Contributor

coleenp commented Sep 14, 2022

/label add hotspot-runtime

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Sep 14, 2022
@openjdk
Copy link

openjdk bot commented Sep 14, 2022

@coleenp
The hotspot-runtime label was successfully added.

@AlanBateman
Copy link
Contributor

I could reproduce the issue with Files.createDirectories on a macos with a trivial program. It appears to be because of the use of NOFOLLOW_LINKS here https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/file/Files.java#L808. To me this appears to be something that either needs to be clarified in the the Files.createDirectories API or addressed/fixed there. I have asked for inputs on this from others who have more knowledge of this area.

The specification is that symbolic links are followed by default, with a few exceptions (like delete and move) where it would be wrong to follow links. Files.createDirectories was originally intended to be like mkdir -p. We'd need to check the history but I suspect it is a long standing bug that createAndCheckIsDirectory opts out of following links.

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks reasonable to me.

There's a potential error case, if parent is not a directory. However, this should lead to an exception later inside Files.newOutputStream(jarfile), so I think it's OK to not check for this.

@openjdk
Copy link

openjdk bot commented Sep 21, 2022

@DamonFool This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 21, 2022
Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Ioi has approved the change but I don't think we should put this workaround into the test library. The issue here is that Files.createDirectories should work like mkdir -p when there are sym links in the tree. Jai is experimenting with a fix to that.

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdraw my approval per Alan's comment.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 21, 2022
@DamonFool
Copy link
Member Author

Withdraw my approval per Alan's comment.

Okay.
Thanks @iklam and @AlanBateman .

@DamonFool
Copy link
Member Author

Close this one since it would be fixed by @jaikiran in a separate pr.
Thanks.

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 hotspot-runtime hotspot-runtime-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

5 participants