Register default file formats on demand instead of at class init - #484
Open
mattjala wants to merge 1 commit into
Open
Register default file formats on demand instead of at class init#484mattjala wants to merge 1 commit into
mattjala wants to merge 1 commit into
Conversation
…ation FileFormat's static initializer registered the default formats by instantiating each implementing class. Every implementing class is a subclass of FileFormat, so whenever a subclass was itself what triggered FileFormat's initialization, the JVM was already initializing that subclass on the same thread. Class.forName then returned immediately rather than waiting, and the instance was built from a class whose own static fields were still unassigned. This specifically became an issue for H4File, though it could easily have happend to NC2File or FitsFile instead. Registration now happens on the first call to a method that consults the list of supported formats. Those calls come from outside any class initialization, so Class.forName completes the subclass before the instance is built. The formats are also a table rather than four copies of the same block, and a format that fails to load no longer stops the ones after it. Fixes HDFGroup#481
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
FileFormat's static initializer registered the default formats by instantiating each implementing class. Every implementing class is a subclass of FileFormat, so whenever a subclass was itself what triggered FileFormat's initialization, the JVM was already initializing that subclass on the same thread. Class.forName then returned immediately rather than waiting, and the instance was built from a class whose own static fields were still unassigned.
This specifically became an issue for H4File, though it could easily have happend to NC2File or FitsFile instead.
Registration now happens on the first call to a method that consults the list of supported formats. Those calls come from outside any class initialization, so Class.forName completes the subclass before the instance is built. The formats are also a table rather than four copies of the same block, and a format that fails to load no longer stops the ones after it.
Fixes #481