Skip to content

Commit

Permalink
Allow empty - but not null - name of PVAStructure elements
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Oct 29, 2023
1 parent 19dba58 commit 0a74a71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/pva/src/main/java/org/epics/pva/data/PVAStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code>
* @throws IllegalArgumentException if an element name is <code>null</code>
*/
public PVAStructure(final String name, final String struct_name, final PVAData... elements)
{
Expand All @@ -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 <code>null</code>
* @throws IllegalArgumentException if an element name is <code>null</code>
*/
public PVAStructure(final String name, final String struct_name, final List<PVAData> 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);
}

Expand Down
3 changes: 3 additions & 0 deletions core/pva/src/test/java/org/epics/pva/data/StructureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0a74a71

Please sign in to comment.