Skip to content

Fix test for trailingEmptyStrict policy validation#1569

Merged
olabusayoT merged 1 commit intoapache:mainfrom
olabusayoT:daf-2217-update-checks
Oct 30, 2025
Merged

Fix test for trailingEmptyStrict policy validation#1569
olabusayoT merged 1 commit intoapache:mainfrom
olabusayoT:daf-2217-update-checks

Conversation

@olabusayoT
Copy link
Contributor

  • Resolved issues with trailingEmptyStrict violation when maxOccurs is '3' by improving checks for empty trailing optional elements.
  • Refactored code to introduce helper functions for error generation and condition checks.

DAFFODIL-2217

Copy link
Contributor

@mbeckerle mbeckerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 just suggest adding comments to code explaining the reasoning.

"Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
)
case _ => // ok
if (checkTrailingOptionalElements(resultOfTry)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments to explain why you need to check first resultOfTry and then priorResultOfTry. Capture some of the reasoning from our debug session.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think a comment explaining this is really important.

For example, why do we need to check both resultOfTry AND priorResultOfTry? My intuition is only the most recently parsed thing should matter for trailing empty since we only care about the trailing thing.

Also, why is this only checked for trailingEmptyStrict? Why do we not need to check for other thingslike PositionTrailingLax?

Copy link
Member

@stevedlawrence stevedlawrence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, minor suggests and needs comments and an explanation why this is the right fix.

}
}

private def ParseErrorEmptyTrailingStrict(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this should be capitalized, it make its usage look like it's calling an object apply method.

if (checkTrailingOptionalElements(resultOfTry)) {
ParseErrorEmptyTrailingStrict(parser, pstate)
} else if (checkTrailingOptionalElements(priorResultOfTry)) {
ParseErrorEmptyTrailingStrict(parser, pstate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blocks of these two if statements are the same, I would suggest just doing something like:

if (checkTrailingOptionalElements(resultOfTry) || checkTrailingOptionalElements(priorResultOfTry) {
  parser.PE(...)
}

"Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
)
case _ => // ok
if (checkTrailingOptionalElements(resultOfTry)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think a comment explaining this is really important.

For example, why do we need to check both resultOfTry AND priorResultOfTry? My intuition is only the most recently parsed thing should matter for trailing empty since we only care about the trailing thing.

Also, why is this only checked for trailingEmptyStrict? Why do we not need to check for other thingslike PositionTrailingLax?

ParseAttemptStatus.AbsentRep,
ParseAttemptStatus.EmptyRep
).contains(resultToTest)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a comment here would be helpful to. MIssing and Absent are both types of Failure parse status, so I would think that indicates error. But I guess because these are optional trailing elements those are not considered errors?

@olabusayoT olabusayoT force-pushed the daf-2217-update-checks branch 2 times, most recently from d5efb54 to b3d17c7 Compare October 13, 2025 17:08
- Resolved issues with trailingEmptyStrict violation when maxOccurs is '3' by improving checks for empty trailing optional elements.
- Refactored code to introduce helper functions for condition checks with appropriate comments

DAFFODIL-2217
@olabusayoT olabusayoT force-pushed the daf-2217-update-checks branch from b3d17c7 to e7e763f Compare October 15, 2025 17:44
Copy link
Contributor

@jadams-tresys jadams-tresys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@olabusayoT olabusayoT merged commit d0dcca0 into apache:main Oct 30, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants