This is an automated email from the ASF dual-hosted git repository. Lukas-Finster pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 143c04d5f5f17e2380b0d57e4a90dff984acc05c Author: Lukas Finster <[email protected]> AuthorDate: Thu Jul 2 13:13:37 2026 +0200 Fix: Guard against NPE in ModelApiReader when service Element is missing in ModelResource (OFBIZ-13443) --- .../apache/ofbiz/ws/rs/model/ModelApiReader.java | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java b/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java index af099d3156..e6110c8cf1 100644 --- a/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java +++ b/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java @@ -25,6 +25,7 @@ import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.base.util.UtilXml; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -104,15 +105,20 @@ public final class ModelApiReader { private static void createOperations(Element resourceEle, ModelResource resource) { for (Element operationEle : UtilXml.childElementList(resourceEle, "operation")) { Element serviceEle = UtilXml.firstChildElement(operationEle, "service"); - String serviceName = UtilXml.checkEmpty(serviceEle.getAttribute("name")).intern(); - ModelOperation op = new ModelOperation() - .path(UtilXml.checkEmpty(operationEle.getAttribute("path")).intern()) - .verb(UtilXml.checkEmpty(operationEle.getAttribute("verb")).intern()).service(serviceName) - .produces(UtilXml.checkEmpty(operationEle.getAttribute("produces")).intern()) - .consumes(UtilXml.checkEmpty(operationEle.getAttribute("consumes")).intern()) - .description(UtilXml.checkEmpty(operationEle.getAttribute("description")).intern()) - .auth(Boolean.parseBoolean(UtilXml.checkEmpty(operationEle.getAttribute("auth")).intern())); - resource.addOperation(op); + if (!UtilValidate.isEmpty(serviceEle)) { + String serviceName = UtilXml.checkEmpty(serviceEle.getAttribute("name")).intern(); + ModelOperation op = new ModelOperation() + .path(UtilXml.checkEmpty(operationEle.getAttribute("path")).intern()) + .verb(UtilXml.checkEmpty(operationEle.getAttribute("verb")).intern()).service(serviceName) + .produces(UtilXml.checkEmpty(operationEle.getAttribute("produces")).intern()) + .consumes(UtilXml.checkEmpty(operationEle.getAttribute("consumes")).intern()) + .description(UtilXml.checkEmpty(operationEle.getAttribute("description")).intern()) + .auth(Boolean.parseBoolean(UtilXml.checkEmpty(operationEle.getAttribute("auth")).intern())); + resource.addOperation(op); + } else { + Debug.logWarning("Error during creation of ModelApi, due to missing 'service' Attribute in ApiModelXml for" + + "ModelResource [%s]", MODULE, resource.getName()); + } } }

