diff --git a/cdm/core/src/main/java/ucar/nc2/internal/ncml/NcmlReader.java b/cdm/core/src/main/java/ucar/nc2/internal/ncml/NcmlReader.java index 9d316d9d02..da0b9fc211 100644 --- a/cdm/core/src/main/java/ucar/nc2/internal/ncml/NcmlReader.java +++ b/cdm/core/src/main/java/ucar/nc2/internal/ncml/NcmlReader.java @@ -810,9 +810,11 @@ private void readDim(Group.Builder groupBuilder, @Nullable Group refGroup, Eleme String nameInFile = dimElem.getAttributeValue("orgName") != null ? dimElem.getAttributeValue("orgName") : name; - // LOOK this is wrong, groupBuilder may already have the dimension. // see if it already exists - Dimension dim = (refGroup == null) ? null : refGroup.findDimension(nameInFile); + Optional dimFromAgg = groupBuilder.findDimension(nameInFile); + Dimension dim = (refGroup == null || dimFromAgg.isPresent()) + ? dimFromAgg.orElse(null) : refGroup.findDimension(nameInFile); + if (dim == null) { // nope - create it String lengthS = dimElem.getAttributeValue("length"); if (lengthS == null) {