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

IDisposable Pattern Cleanup and fix TestDictionary.TestResourceCleanup, #265 #1095

Merged
merged 2 commits into from
Jan 12, 2025

Conversation

paulirwin
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Some minor cleanup of IDisposable pattern implementations, and a bug fix.

Fixes #265

Description

I did a review of all implementations of IDisposable.Dispose() to ensure they follow the Dispose Pattern correctly, and someone had clearly already done all of the hard work here: it was nearly all done right. There were a couple cases that I fixed in this PR:

  • Lucene42DocValuesConsumer.SortedSetEnumerator did not implement the pattern correctly, but it also is an internal type with no subclasses, so this was made sealed.
  • Hunspell's TestDictionary.CloseCheckInputStream had a curious shadowing of Dispose that was causing it to not work correctly, and this exposed a bug: the stream wrapper was getting disposed of in Hunspell.Dictionary, when it is expected to not be disposed of. The shadowed Dispose method was never called, even if the Dictionary code actually did dispose of the wrapper. This created a false negative, where the test thought it wasn't disposed of when it actually was. This PR fixes that by removing the shadowing Dispose method, marking this.disposed in the actual Dispose pattern override method so that it's properly marked when called virtually, and leaving the stream open in the Dictionary.ReadDictionaryFiles method to match Java's behavior (and the expected behavior per the unit test).

@paulirwin paulirwin added the notes:bug-fix Contains a fix for a bug label Jan 12, 2025
@NightOwl888 NightOwl888 merged commit ad5d70a into apache:master Jan 12, 2025
265 checks passed
@paulirwin paulirwin deleted the issue/265-2 branch January 12, 2025 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:bug-fix Contains a fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Review to ensure IDisposable is being used correctly and disposable pattern implemented correctly
2 participants