Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor / Avoid NPE when saving invalid document for an element not existing in the model #5251

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions core/src/main/java/org/fao/geonet/kernel/EditLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,15 @@ private void doAddFragmentFromXpath(MetadataSchema metadataSchema,
propEl.addContent(child);
} else if (childHasSameTypeAsTarget) {
Element parent = propEl.getParentElement();
int index = parent.indexOf(propEl);
parent.addContent(index, child);
if (parent == null) {
LOGGER_ADD_ELEMENT.error(String.format(
" > adding fragment from XPath in element %s which has no parent. This usually means that the element is not allowed in the XSD. Check this element in the metadata record.",
propEl.getName()
));
} else {
int index = parent.indexOf(propEl);
parent.addContent(index, child);
}
} else {
// Add an element of same type in the target node
final Element newElement = addElement(metadataSchema, propEl, child.getQualifiedName());
Expand Down