stevedlawrence commented on code in PR #1603:
URL: https://github.com/apache/daffodil/pull/1603#discussion_r2627332338
##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/NilParsers.scala:
##########
@@ -40,21 +40,40 @@ abstract class LiteralNilOfSpecifiedLengthParserBase(erd:
ElementRuntimeData)
def isFieldNilLit(field: String): Boolean
override def parse(start: PState): Unit = {
-
- val field = parseString(start)
-
- val isFieldEmpty = field.length() == 0
-
- if (isFieldEmpty && isEmptyAllowed) {
- // Valid! Success ParseResult indicates nilled
- } else if (isFieldEmpty && !isEmptyAllowed) {
- // Fail!
- PE(start, "%s - Empty field found but not allowed!", eName)
- } else if (isFieldNilLit(field)) {
- // Contains a nilValue, Success ParseResult indicates nilled
+ if (erd.isComplexType) {
+ // nillable complex types must have a nilValue of %ES;. For a literal
nil specified length
+ // complex to be nilled, that means either there must be a specified
length that is zero
+ // or there isn't a specified length and we have reached the end of the
data. If neither
+ // of these conditions are true, then there is non-empty data for this
complex element and
+ // it cannot be nilled.
+ val bitLimit0b = start.bitLimit0b
+ val hasSpecifiedLength = bitLimit0b.isDefined
+ if (
+ (hasSpecifiedLength && (bitLimit0b.get - start.bitPos0b) > 0) ||
+ (!hasSpecifiedLength && start.dataInputStream.hasData)
+ ) {
+ // Fail!
+ PE(start, "%s - Does not contain a nil literal!", eName)
Review Comment:
This was copied from the below messages. Agreed that this isn't standard
with our normal phrasing of errors--I'll remove it from the others too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]