Skip to content

Commit

Permalink
fix(plc4j/codgen): fixed data reader complex working with a empty log…
Browse files Browse the repository at this point in the history
…ical name
  • Loading branch information
sruehl committed Oct 25, 2021
1 parent 02e102c commit 2ebc8a6
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.plc4x.java.spi.codegen.io;

import org.apache.commons.lang3.StringUtils;
import org.apache.plc4x.java.spi.generation.ByteOrder;
import org.apache.plc4x.java.spi.generation.ParseException;
import org.apache.plc4x.java.spi.generation.ReadBuffer;
Expand Down Expand Up @@ -63,9 +64,13 @@ public T read(String logicalName, WithReaderArgs... readerArgs) throws ParseExce
}

public T read(String logicalName, ComplexTypeSupplier<T> complexSupplier, WithReaderArgs... readerArgs) throws ParseException {
readBuffer.pullContext(logicalName,readerArgs);
// TODO: it might be even better if we default to value like in other places... on the other hand a complex type has always a proper logical name so this might be fine like that
boolean hasLogicalName = StringUtils.isNotBlank(logicalName);
if (hasLogicalName)
readBuffer.pullContext(logicalName, readerArgs);
final T t = complexSupplier.get();
readBuffer.closeContext(logicalName,readerArgs);
if (hasLogicalName)
readBuffer.closeContext(logicalName, readerArgs);
return t;
}

Expand Down

0 comments on commit 2ebc8a6

Please sign in to comment.