Repository navigation
Conversation
* Add a static HDF5NativeLibrary.load() method
mkitti
left a comment
There was a problem hiding this comment.
Thanks, moving the loading into the main code is the right fix: downstream code had no way to load hdf5_java itself. I built n5-hdf5 saalfeldlab/n5-hdf5#50 against this branch, and it passes with no workaround (47 tests, 5 skipped, same as its master).
Blocking: class-initialization order. Five public enums initialize their constants from HDF5Constants:
IHDF5WriterConfigurator.FileFormatVersionHDF5DataClassHDF5StorageLayoutHDF5EnumerationType.EnumStorageFormCharacterEncoding
If any of them, or anything using them, is touched before HDF5Factory/HDF5FactoryProvider/HDFHelper, HDF5Constants runs H5.loadH5Lib() before load(). H5's class initialization then fails, and since that's permanent in Java, every later HDF5 call fails too (UnsatisfiedLinkError: 'int hdf.hdf5lib.H5.H5dont_atexit()').
- CI: that's the 306 macOS failures here.
HDF5ArchiverTesttouchesFileFormatVersionBoundsfirst, and Linux passes only because of its test order. The removedNativeLibraryBootstrapused to hide it. - Downstream: reading
CharacterEncoding.UTF8beforeHDF5Factory.open(...)fails the same way. - Scope: initializing each class of the jar first in a fresh JVM, 15 of 1,104 classes break HDF5 this way.
Smaller:
loaded = trueis set before loading succeeds, so after one failure later callers skipload()silently and only see the error above.System.setProperty(..., Loader.load(...))throws ifLoader.load()returnsnull, which it does when JavaCPP's library loading is disabled.
I've put fixes for all three in #14, stacked on this PR: enum constants read HDF5 values through HDF5NativeLibrary.intConstant(() -> ...)/longConstant(...), which call load() first. With it, 0 of 1,104 classes fail. #14's CI passes on macOS and Linux (Java 8 and 21) without the bootstrap; Windows still fails only with the separate-HDF5-libraries error that bytedeco/javacpp-presets#1814 fixes.
Compatibility with javacpp-presets #1814: once bytedeco/javacpp-presets#1814 is in, hdf5_java's own static initializer also sets hdf.hdf5lib.H5.hdf5lib, to the same path. This PR is still needed after that, because something has to load hdf5_java first. The extra setProperty is just redundant.
🤖 Generated with Claude Code
This or something like it will be needed in updating n5-hdf5.
(with help from Claude)