-
Notifications
You must be signed in to change notification settings - Fork 641
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
fix: Aligned disposable patterns #746
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
The token streams are still a WIP (see #271 (comment)), but I think having them set up consistently for .NET is a good starting point even if we eventually change them back to using Close()
instead of Dispose()
. So, we can keep those changes in this PR.
There are just a couple of minor changes to do before this can be accepted. See the comments inline.
src/Lucene.Net.Spatial/Prefix/AbstractVisitingPrefixTreeFilter.cs
Outdated
Show resolved
Hide resolved
It looks like this was mainly done to prevent the end user from being able to override the default |
I took a look and the only thing that // LUCENENET specific: Since FileStream does its own buffering, this class was refactored
// to do all checksum operations as well as writing to the FileStream. By doing this we elminate
// the extra set of buffers that were only creating unnecessary memory allocations and copy operations. So, the inheritance chain was left unchanged (for consistency with Lucene), but we aren't actually using the functionality of the base class. Instead, we call The This looks fine. |
FYI - The |
…lict with other work that has been done to CharArrayMap
…Lucene to implement the disposable pattern properly.
…of Dispose() and Dispose(bool) to align with other classes
@nikcio - Thanks again for doing this. Your help is really appreciated. I went ahead and updated the comments to finish this up (for the most part). We will know what else needs to be done in the scan, and we are tracking #265 and we also have a plan to fix #271. I didn't do anything with |
Related to #265
I've run through most of the issues reported in Sonarcloud related to the use of the IDisposable pattern (https://sonarcloud.io/project/issues?resolved=false&rules=csharpsquid%3AS3881&id=apache_lucenenet)
This PR is meant to further expose which implementations of the pattern require more investigation while also removing the easiest areas where the pattern just needs a simple alignment. This means that if any of the following changes exposes an issue requiring much more effort this is best to be moved to comment on the existing issue and have a solution opened in another PR. I realize that a correct implementation of this pattern can be advanced and is related to at least a handful of issues opened in this repository which is why I want to take the approach stated 😄 .
To help the review I've outlined the changes here in some categories:
Issues from private classes were marked
sealed
Private classes don't have to uphold the same pattern as other classes if they are marked
sealed
.Basic implementation of pattern in some classes
The following files had a class where the following template was implemented.
base.Dispose(disposing)
referencing codeThe
base.Dispose(disposing)
line inBufferedCharFilter
references the dispose method inLucene.Net.Analysis.CharFilter
base.Dispose(disposing)
referencing disposing methods inSystem.IO
The changes in the following files have
base.Dispose(disposing)
methods which reference code inSystem.IO
Fixed
GC.SuppressFinalize
callIn
PrefixCodedTerms
the call toGC.SuppressFinalize
had the object parameter set totrue
instead ofthis
FSDirectory
There's a commented
base.Disposing(disposed)
change inFSDirectory
which when activated causes at least 140 tests to fail (I didn't run it all the way through when I noticed the error). Please validate that theDispose(bool)
method isn't supposed to call its base.Other
base.Dispose(dispoing)
Other places that aren't part of the categories above reference an empty
Dispose(bool)
method in its base. Therefore, this shouldn't cause any side effects and only make future development more reliable as the classes will follow the same dispose pattern.Sidenote
Assuming the comment around this
Dispose
method is correct this issue can be removed as intended either in SonarCloud or in source: https://sonarcloud.io/project/issues?issues=AYRH0T17_qq9ReJdi40Q&open=AYRH0T17_qq9ReJdi40Q&id=apache_lucenenet