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

Fixes a bug when failing assertions on DirectoryStream types #3036

Merged

Conversation

ascopes
Copy link
Contributor

@ascopes ascopes commented May 7, 2023

The DirectoryStream class is somewhat special because the API allows it to only support .iterator() being called at most once on any implementations. Due to the nature of how the StandardRepresentation currently works for iterable types, any assertion error that is thrown as a result of assertions failing on a DirectoryStream object can result in IllegalStateExceptions being propagated to the caller if .iterator() has already been called on the class. This can break further if using soft assertions, as the state of the class could change unexpectedly resulting in different exceptions being raised depending on the execution order.

I've added a mechanism to deal with allowing the definition of so-called 'blacklisted' iterable types, just in case other cases like this appear in the JRE standard library anywhere in the future. This will prevent unexpected errors occuring when dealing with the NIO FileSystem APIs.

This was discovered as a result of ascopes/java-compiler-testing#450, where @marschall pointed out that the #iterator() on a DirectoryStream should only be called once in some implementations.

@ascopes ascopes force-pushed the bugfix/assert-on-directory-streams branch 2 times, most recently from a3da260 to f2fdf62 Compare May 7, 2023 14:07
@joel-costigliola
Copy link
Member

Thanks for the analysis and the PR @ascopes

Copy link
Member

@joel-costigliola joel-costigliola 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, just minor comments

The DirectoryStream class is somewhat special because the API allows it
to only support .iterator() being called at most once on any
implementations. Due to the nature of how the StandardRepresentation
currently works for iterable types, any assertion error that
is thrown as a result of assertions failing on a DirectoryStream
object can result in IllegalStateExceptions being propagated to
the caller if .iterator() has already been called on the class.
This can break further if using soft assertions, as the state of
the class could change unexpectedly resulting in different
exceptions being raised depending on the execution order.

I've added a mechanism to deal with allowing the definition of
so-called 'blacklisted' iterable types, just in case other
cases like this appear in the JRE standard library anywhere
in the future. This will prevent unexpected errors occuring
when dealing with the NIO FileSystem APIs.
@ascopes ascopes force-pushed the bugfix/assert-on-directory-streams branch from f2fdf62 to 51792a2 Compare May 8, 2023 10:07
@ascopes
Copy link
Contributor Author

ascopes commented May 8, 2023

@joel-costigliola updated. Thanks for the quick response.

@joel-costigliola joel-costigliola merged commit 5f7b722 into assertj:main May 8, 2023
9 checks passed
@joel-costigliola
Copy link
Member

Integrated thanks @ascopes !

@ascopes ascopes deleted the bugfix/assert-on-directory-streams branch May 24, 2023 12:22
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.

None yet

2 participants