Possible bug in H5CompoundDS causes hdf.object to depend on hdf.view


I am writing a Java program to convert a legacy format to HDF5 using the Java HDF Object Package. It has been working very well so far, but I was stopped by an error today when I tried to update my code from using the 3.0 pre-release of the Java HDF Object Package to the 3.0 release version.

At one point in my code, I create a compound dataset compoundDS without any data. I then get the data buffer from the compound dataset by the line

List compoundFields = (List) compoundDS.getData();

However, with the 3.0 release version, this crashes with the following error:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at hdf.object.h5.H5CompoundDS.read(Unknown Source)
	at hdf.object.Dataset.getData(Unknown Source)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(Unknown Source)
	at org.eclipse.swt.SWT.error(Unknown Source)
	at org.eclipse.swt.SWT.error(Unknown Source)
	at org.eclipse.swt.widgets.Display.error(Unknown Source)
	at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
	at org.eclipse.swt.widgets.Display.create(Unknown Source)
	at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
	at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
	at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
	at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
	at hdf.view.Tools.<clinit>(Unknown Source)
	... 5 more

It seems that there is some local SWT trouble on my platform (macOS 10.13.6 using both Java 8 and 10). However, the more troubling part is that the Java HDF Object Package somehow depends on SWT at all!

I’ve dug into this a bit today, and it turns out that H5CompoundDS.java imports hdf.view.Tools in order to call Tools.getJavaObjectRuntimeClass(Object) in the H5CompoundDs.read() function. Importing hdf.view.Tools then probably causes my specific problem because of the static SWT stuff that Tools sets up. The more fundamental problem, though, is that this connection from hdf.object.h5.H5CompoundDS to hdf.view.Tools breaks the separation of the Java HDF Object Package, which means that it now cannot be used independently of hdf.view. As no other files in hdf.object seem to import from hdf.view, I assume that this is a mistake?

I do not believe that this would be difficult to fix, however; Tools.getJavaObjectRuntimeClass(Object) is a simple self-contained function, and it could be moved to somewhere else, either in hdf.object or hdf.hdf5lib. Someone more knowledgeable than me might be able to find a good place for it.


Yes, the reference to hdfview classes is a mistake. Our goal with the switch to SWT was to disconnect the dependency on visual libraries.
We will review our code for this issue.

Thanks for reporting this,


Happy to help! :slight_smile:

I managed to fairly smoothly get around the bug on my end as well by including the data when creating compoundDS instead of creating it as an empty dataset and then inserting the data later.