From 26ee6582c87299114d070e13b3af1f11a63041c7 Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Mon, 15 Apr 2024 13:30:00 +0200 Subject: [PATCH] Fix renamed dimension in aggregations where refGroup may be null --- .../src/main/java/ucar/nc2/internal/ncml/NcmlReader.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..df76a96854 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) {