Skip to content

Commit 785b618

Browse files
committed
Handle NULL string attributes in HDF5.
Both old and new APIs.
1 parent 23790f6 commit 785b618

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

cdm/core/src/main/java/ucar/nc2/internal/iosp/hdf5/H5headerNew.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public class H5headerNew implements H5headerIF, HdfHeaderIF {
9393
private static boolean warnings = true, debugReference, debugRegionReference, debugCreationOrder, debugStructure;
9494
private static boolean debugDimensionScales;
9595

96+
// NULL string value, following netCDF-C, set to NIL
97+
private static final String NULL_STRING_VALUE = "NIL";
98+
9699
public static void setWarnings(boolean warn) {
97100
warnings = warn;
98101
}
@@ -2135,6 +2138,9 @@ Array getHeapDataArray(HeapIdentifier heapId, DataType dataType, int endian)
21352138
*/
21362139
String readHeapString(long heapIdAddress) throws IOException {
21372140
HeapIdentifier heapId = h5objects.readHeapIdentifier(heapIdAddress);
2141+
if (heapId.isEmpty()) {
2142+
return NULL_STRING_VALUE;
2143+
}
21382144
GlobalHeap.HeapObject ho = heapId.getHeapObject();
21392145
if (ho == null)
21402146
throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId);
@@ -2154,6 +2160,9 @@ String readHeapString(long heapIdAddress) throws IOException {
21542160
*/
21552161
String readHeapString(ByteBuffer bb, int pos) throws IOException {
21562162
HeapIdentifier heapId = h5objects.readHeapIdentifier(bb, pos);
2163+
if (heapId.isEmpty()) {
2164+
return NULL_STRING_VALUE;
2165+
}
21572166
GlobalHeap.HeapObject ho = heapId.getHeapObject();
21582167
if (ho == null)
21592168
throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId);

cdm/core/src/main/java/ucar/nc2/iosp/hdf5/H5header.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class H5header extends NCheader implements H5headerIF {
6060
private static boolean warnings = true, debugReference, debugRegionReference, debugCreationOrder, debugStructure;
6161
private static boolean debugDimensionScales;
6262

63+
// NULL string value, following netCDF-C, set to NIL
64+
private static final String NULL_STRING_VALUE = "NIL";
65+
6366
public static void setWarnings(boolean warn) {
6467
warnings = warn;
6568
}
@@ -4711,6 +4714,9 @@ Array getHeapDataArray(HeapIdentifier heapId, DataType dataType, int endian)
47114714
*/
47124715
String readHeapString(long heapIdAddress) throws IOException {
47134716
H5header.HeapIdentifier heapId = new HeapIdentifier(heapIdAddress);
4717+
if (heapId.isEmpty()) {
4718+
return NULL_STRING_VALUE;
4719+
}
47144720
H5header.GlobalHeap.HeapObject ho = heapId.getHeapObject();
47154721
if (ho == null)
47164722
throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId);
@@ -4730,6 +4736,9 @@ String readHeapString(long heapIdAddress) throws IOException {
47304736
*/
47314737
String readHeapString(ByteBuffer bb, int pos) throws IOException {
47324738
H5header.HeapIdentifier heapId = new HeapIdentifier(bb, pos);
4739+
if (heapId.isEmpty()) {
4740+
return NULL_STRING_VALUE;
4741+
}
47334742
H5header.GlobalHeap.HeapObject ho = heapId.getHeapObject();
47344743
if (ho == null)
47354744
throw new IllegalStateException("Cant find Heap Object,heapId=" + heapId);

0 commit comments

Comments
 (0)