Skip to content

Store the last added child in the PState for use in separator logic#889

Merged
stevedlawrence merged 1 commit intoapache:mainfrom
stevedlawrence:daffodil-2755-null-pointer
Dec 9, 2022
Merged

Store the last added child in the PState for use in separator logic#889
stevedlawrence merged 1 commit intoapache:mainfrom
stevedlawrence:daffodil-2755-null-pointer

Conversation

@stevedlawrence
Copy link
Member

In some cases, separator logic needs knowledge about the most recently added child of an element. This is currently handled by examining the infoset and finding its last child element using the maybeMostRecentlyAddedChild function.

The problem with this approach is that the InfosetWalker is allowed to "release" elements from the infoset that it thinks are no longer needed. There isn't a good way to tell the infoset that these last children are potentially still needed for separator logic, and so it could actually release them prior to the separator logic trying to access them, which leads to a null pointer exception.

To fix this, this modifies the PState to add a slot for the last modified child of the current infoset element, and modifies the ElementParser's to set this state appropriately. This way, the InfosetWalker is free to remove elements as it normally does, but the last child is still available when needed.

This also removes the maybeMostRecentlyAddedChild functions since this kind of access to the infoset can lead to null pointers.

Also modifies the SAXInfosetOutputter to check isNilled correctly, which supports checking if complex elements are nilled without being final yet. For similar reasons, modifies the InfosetWalker so that it does not walk into Complex elements if there is a chance that it could be nilled and we might not be sure.

DAFFODIL-2755

In some cases, separator logic needs knowledge about the most recently
added child of an element. This is currently handled by examining the
infoset and finding its last child element using the
maybeMostRecentlyAddedChild function.

The problem with this approach is that the InfosetWalker is allowed to
"release" elements from the infoset that it thinks are no longer needed.
There isn't a good way to tell the infoset that these last children are
potentially still needed for separator logic, and so it could actually
release them prior to the separator logic trying to access them, which
leads to a null pointer exception.

To fix this, this modifies the PState to add a slot for the last
modified child of the current infoset element, and modifies the
ElementParser's to set this state appropriately. This way, the
InfosetWalker is free to remove elements as it normally does, but the
last child is still available when needed.

This also removes the maybeMostRecentlyAddedChild functions since this
kind of access to the infoset can lead to null pointers.

Also modifies the SAXInfosetOutputter to check isNilled correctly, which
supports checking if complex elements are nilled without being final
yet. For similar reasons, modifies the InfosetWalker so that it does not
walk into Complex elements if there is a chance that it could be nilled
and we might not be sure.

DAFFODIL-2755
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 Very clean and small change.

Copy link
Contributor

@tuxji tuxji left a comment

Choose a reason for hiding this comment

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

+1

Looks good to me 👍

@stevedlawrence stevedlawrence merged commit 5e6a113 into apache:main Dec 9, 2022
@stevedlawrence stevedlawrence deleted the daffodil-2755-null-pointer branch December 9, 2022 12:43
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.

3 participants