8349107: Remove RMI finalizers #4
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
3 finalizers in RMI code can be removed, as they do not perform meaningful cleanup.
jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContextRegistryContext.finalize()just callsclose(). Theclose()method does not perform any cleanup per se, but rather "helps the garbage collector" by settingenvironmentandregistrytonull.jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.BindingEnumerationBindingEnumeration.finalize()simply callsclose()on thectxfield, itself aRegistryContext(andclose()just "helps the GC.")src/java.rmi/share/classes/sun/rmi/log/LogInputStreamLogInputStreamtracks its length with an int field,length. Iflengthever becomes == 0,LogInputStream's methods will return without doing anything.The finalizer calls
close(), which just sets length = 0.By the time a
LogInputStreambecomes unreachable and is finalized, it's a moot point whether length == 0, as no more methods can be called.If anything, this finalizer could cause a bug. If a
LogInputStreamwere to became unreachable while a method were still running, the finalizer could set the length to 0 while method code is still running and expecting a length != 0.It's possible that there is a very long standing bug that
close()should be callingin.close(), in which case this evaluation will need to be revisited.