Skip to content

Conversation

@bplb
Copy link
Member

@bplb bplb commented Nov 18, 2025

Slightly changes the specification of Files.createDirectory to highlight that it fails if a filesystem entity already exists at the given location.


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-8220816: (fs) Files.createDirectory should make it more obvious that it fails when the directory already exists (Enhancement - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28378

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 18, 2025

👋 Welcome back bpb! 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
Copy link

openjdk bot commented Nov 18, 2025

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

8220816: (fs) Files.createDirectory should make it more obvious that it fails when the directory already exists

Reviewed-by: alanb, jpai

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 57 new commits pushed to the master branch:

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 nio nio-dev@openjdk.org label Nov 18, 2025
@openjdk
Copy link

openjdk bot commented Nov 18, 2025

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

  • nio

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 rfr Pull request is ready for review label Nov 18, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 18, 2025

Webrevs

Copy link
Member

@justin-curtis-lu justin-curtis-lu left a comment

Choose a reason for hiding this comment

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

Wording looks reasonable to me. I presume the CSR will be filed after wording is finalized.

* if the array contains an attribute that cannot be set atomically
* when creating the directory
* @throws FileAlreadyExistsException
* if a directory could not otherwise be created because a file of
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth clarifying ..."file or directory"... in the throws tag as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it worth clarifying ..."file or directory"... in the throws tag as well?

Yes, I think so, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in commit 3af3490.

@bplb
Copy link
Member Author

bplb commented Nov 18, 2025

I presume the CSR will be filed after wording is finalized.

Yes. I generally wait for the discussion to converge before filing the CSR.

@bplb
Copy link
Member Author

bplb commented Nov 18, 2025

Please note that this was discussed before on nio-dev.

* @throws FileAlreadyExistsException
* if a directory could not otherwise be created because a file of
* that name already exists <i>(optional specific exception)</i>
* if a directory could not otherwise be created because a file or
Copy link
Contributor

Choose a reason for hiding this comment

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

It is pre-existing wording, but I don't know that "otherwise" has any meaning here.
It reads the same whether "otherwise" is present or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know that "otherwise" has any meaning here.

No, I also don't think it does.

@AlanBateman
Copy link
Contributor

AlanBateman commented Nov 19, 2025

I think the @throws FileAlreadyExistsException description could be improved as "because a file of that name already exists" is too subtle. If we do change it then it will need to be done for all the methods that throw this exception, not just Files.createDirectory. What do you think of keeping it as simple as "If dir locates a file that already exists" ?

Files.createFile has "Creates a new and empty file, failing if the file already exists", which I think is clear. It's less easy to create a sentence for createDirectory, createSymbolicFile and other methods. "Creates a directory, failing if the file already exists" is accurate but might not be clear to everyone that "file" means any file (sym link, directory, ...). I wonder if we could keep simple like this: "Creates a directory, failing if dir locates an existing file". I would be hesitate to using "file or directory" as proposed because that's just two of many cases.

@bplb
Copy link
Member Author

bplb commented Nov 19, 2025

What do you think of keeping it as simple as "If dir locates a file that already exists" ?

That's fine. I previously suggested {@code dir} already exists here.

"Creates a directory, failing if dir locates an existing file".

That might work.

@bplb
Copy link
Member Author

bplb commented Nov 19, 2025

Commit 5c62cd5 does not (yet) address throws FileAlreadyExistsException verbiage for these cases:

  1. If a file of that name already exists and the CREATE_NEW option is specified;
  2. if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified.

* @throws FileAlreadyExistsException
* if {@code dir} exists but is not a directory <i>(optional specific
* exception)</i>
* if {@code dir} locates an existing file but is not a directory
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "that is not a directory" might be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cf6ede.

/**
* Creates a new and empty file, failing if the file already exists. The
* Creates a new and empty file, failing if {@code path} locates an existing
* file. The
Copy link
Contributor

Choose a reason for hiding this comment

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

That works. I assume you'll re-flow this a bit to avoid "file. The" be on its own.

Copy link
Member Author

Choose a reason for hiding this comment

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

I assume you'll re-flow this a bit

I left it that way intentionally to ease comparing the diffs in progress.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cf6ede.

/**
* Creates a new link (directory entry) for an existing file <i>(optional
* Creates a new link (directory entry) for an existing file,
* failing if {@code link} locates an existing file <i>(optional
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit, I think the comment has got mis-aligned.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cf6ede.

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.

Good, thanks for the updates.

A coin toss as to whether it needs a CSR as there isn't anything new or changed.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 19, 2025
@bplb
Copy link
Member Author

bplb commented Nov 19, 2025

Good, thanks for the updates.

Thanks for the review.

Are we not concerned about the other FAEEs mentioned above?

@AlanBateman
Copy link
Contributor

Are we not concerned about the other FAEEs mentioned above?

Some of them are okay, e.g. copy has "if the target file exists but ...".

If you have cycles, there are 7 cases that have "If a file of that name already exists and the CREATE_NEW ..." that could be improved if changed to "If the path locates an existing file and the CREATE_NEW ...".

@bplb
Copy link
Member Author

bplb commented Nov 19, 2025

If you have cycles, there are 7 cases [...] that could be improved [...]

Yes, I will change them.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Nov 19, 2025
@bplb
Copy link
Member Author

bplb commented Nov 19, 2025

If you have cycles, there are 7 cases that have "If a file of that name already exists and the CREATE_NEW ..." that could be improved if changed to "If the path locates an existing file and the CREATE_NEW ...".

Addressed in commit 3684b8c.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 19, 2025
@jaikiran
Copy link
Member

Hello Brian, the changes look reasonable to me.

Having said that, the JBS issue description states that the usage of the word "file" makes it sound like the exception is raised only if a regular file exists at the Path. Specifically, the previous wording was:

If a file of that name already exists

and with the proposed change we now have:

If the path locates an existing file

So, I think, that wording will still leave readers wondering whether existing directory at that Path are considered when throwing that exception.

I am not proposing further changes though (I can't think of something that's more concise). Files.exists(Path) too uses the word "file":

Tests whether a file exists.

and it checks even for directories, so I think it's all consistent with the rest of the API docs.

@AlanBateman
Copy link
Contributor

Having said that, the JBS issue description states that the usage of the word "file" makes it sound like the exception is raised only if a regular file exists

I think it's best to keep the API docs simple and consistent. I'm sure there are developers that don't think of a directory or sym files as "files" but once you attempt to clarify things then it gets complicated and it could potentially confusing a wider set of developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nio nio-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

5 participants