From 0a74a714896b7e4e2325a9e6c44846a72dcf6571 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Sun, 29 Oct 2023 10:28:59 +0100 Subject: [PATCH] Allow empty - but not null - name of PVAStructure elements --- .../main/java/org/epics/pva/data/PVAStructure.java | 12 ++++++------ .../test/java/org/epics/pva/data/StructureTest.java | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java index 6f0c424188..88bb0ac667 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java @@ -81,8 +81,8 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f /** @param name Name of the structure (may be "") * @param struct_name Type name of the structure (may be "") - * @param elements Elements, must be named - * @throws IllegalArgumentException when an element is not named + * @param elements Elements, name may be "", but not null + * @throws IllegalArgumentException if an element name is null */ public PVAStructure(final String name, final String struct_name, final PVAData... elements) { @@ -91,16 +91,16 @@ public PVAStructure(final String name, final String struct_name, final PVAData.. /** @param name Name of the structure (may be "") * @param struct_name Type name of the structure (may be "") - * @param elements Elements, must be named - * @throws IllegalArgumentException when an element is not named + * @param elements Elements, name may be "", but not null + * @throws IllegalArgumentException if an element name is null */ public PVAStructure(final String name, final String struct_name, final List elements) { super(name); this.struct_name = struct_name; for (PVAData element : elements) - if (element.getName().isEmpty()) - throw new IllegalArgumentException("Structure with unnamed element"); + if (element.getName() == null) + throw new IllegalArgumentException("Structure with null element name"); this.elements = Collections.unmodifiableList(elements); } diff --git a/core/pva/src/test/java/org/epics/pva/data/StructureTest.java b/core/pva/src/test/java/org/epics/pva/data/StructureTest.java index 8254f96d3d..149ff3ab1b 100644 --- a/core/pva/src/test/java/org/epics/pva/data/StructureTest.java +++ b/core/pva/src/test/java/org/epics/pva/data/StructureTest.java @@ -127,7 +127,10 @@ public void testError() // But _elements_ of the structure need names to address them try { + // This is OK, i.e. element names may be empty new PVAStructure("", "", new PVADouble("")); + // But this must fail, element names must be non-null + new PVAStructure("", "", new PVADouble(null)); fail("Structure elements must be named"); } catch (Exception ex)