Skip to content
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

Improve message if file exists instead of folder #1568

Merged

Conversation

stefanbirkner
Copy link
Contributor

When TemporaryFolder(String path) or TemporaryFolder(String... paths) is
called with a path that matches the path of an existing file then an
IOException with a message like "a file with path exists" is
thrown.

continue;
} else if (file.exists()) {
throw new IOException(
"a file with the path \'" + relativePath.getPath() + "\' exists");
Copy link
Contributor

Choose a reason for hiding this comment

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

We can include already in the message, as createNewFile includes it in 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.

I was thinking about the word "already" for this message two. But it is wrong here because the user wants to create a folder and not a file. Therefore we cannot say the file is already there.

"could not create a folder with the path \'" + relativePath.getPath() + "\'");
if (!lastMkdirsCallSuccessful) {
if (file.exists() && file.isDirectory()) {
continue;
Copy link
Member

Choose a reason for hiding this comment

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

I think we could avoid the continue by moving the !file.isDirectory() back into the enclosing if and remove the first inner if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Fixed.

@marcphilipp marcphilipp added this to the 4.13 milestone Oct 31, 2018
When TemporaryFolder(String path) or TemporaryFolder(String... paths) is
called with a path that matches the path of an existing file then an
IOException with a message like "a file with path <path> exists" is
thrown.
@stefanbirkner stefanbirkner force-pushed the temporary-folder-file-exists branch from 3e6be76 to 10a863e Compare November 1, 2018 09:40
@stefanbirkner stefanbirkner merged commit 10a863e into junit-team:master Nov 1, 2018
@stefanbirkner stefanbirkner deleted the temporary-folder-file-exists branch November 1, 2018 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants