Checking this behavior, I have noted that this is caused by a difference in the way that jsf ri implements UIComponentBase.getChildren and myfaces.
The idea when you add a child component to some other component is that child.getParent return the component where it was added. The line:
this is the context:
UIComponent referencedComponent = new HtmlInputText();
facesContext.addMessage(referencedComponent.getId(), new FacesMessage(
FacesMessage.SEVERITY_ERROR, "summary", "detail"));
set the parent to the base component first and then add it. But checking the implementation on myfaces, when the component is added it is also set the parent property, so this code is useless. If exists on the children list, it is removed first and added later.
I think based on the message of jsf ri:
java.lang.IllegalStateException: Parent was not null, but this component not related
when is added, the parent try to check if is on the children list (Note that this do not exists in reality, because there is no add yet). The result on jsf ri is an IllegalStateException, because it try to remove a child component that in fact does not exists.
The solution is simple: just remove or comment the line:
on both test.
If no objections I'll commit this change.