Skip to content

Make FilenameUtils.equals() not throw an exception#154

Merged
garydgregory merged 3 commits into
apache:masterfrom
mernst:filenameutils-equals
Oct 1, 2020
Merged

Make FilenameUtils.equals() not throw an exception#154
garydgregory merged 3 commits into
apache:masterfrom
mernst:filenameutils-equals

Conversation

@mernst

@mernst mernst commented Sep 14, 2020

Copy link
Copy Markdown
Contributor

It is surprising that FilenameUtils.equals can throw NullPointerException, because:

  • such behavior is outside the ordinary contract of equals(), and
  • FilenameUtils.equals throws NullPointerExceptioneven if the client did not pass null as an argument. It throws NullPointerExceptioneven if one of the arguments is not a valid, normalizable filename. However, this behavior is not documented.

This pull request:

  • documents the requirement that the arguments must be valid,
  • makes the exception message more specific, indicating the filename that was invalid, and
  • throws IllegalArgumentException instead of NullPointerException.

@coveralls

coveralls commented Sep 15, 2020

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.003%) to 89.494% when pulling f59813b on mernst:filenameutils-equals into cdf7794 on apache:master.

@garydgregory

Copy link
Copy Markdown
Member

I see the current implementation and this PR as incorrect, the method should never throw IMO. The normalization returns null, then the method should return false.

@mernst

mernst commented Sep 15, 2020

Copy link
Copy Markdown
Contributor Author

I agree that change is better. I was aiming for minimal changes to the existing specification and tests.
I have now changed the method to return false rather than throwing an exception.

@mernst mernst changed the title Improve exception thrown by FilenameUtils.equals() Make FilenameUtils.equals() not throw an exception Sep 30, 2020
@mernst

mernst commented Sep 30, 2020

Copy link
Copy Markdown
Contributor Author

@garydgregory What do you think of the revised pull request that makes equals not throw an exception?

@garydgregory garydgregory merged commit 4370bce into apache:master Oct 1, 2020
asfgit pushed a commit that referenced this pull request Oct 1, 2020
@mernst mernst deleted the filenameutils-equals branch January 5, 2021 23: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