This is an automated email from the ASF dual-hosted git repository.

gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git


The following commit(s) were added to refs/heads/main by this push:
     new ff60c4326b Fix getDecisionService method NPE (#6740)
ff60c4326b is described below

commit ff60c4326b9f0f57bbbe0a0be8a2593a058fb46c
Author: Yeser Amer <[email protected]>
AuthorDate: Wed Jun 3 09:48:37 2026 +0200

    Fix getDecisionService method NPE (#6740)
    
    * Fix getDecisionService method NPE
    
    * Tests
---
 .../kie/dmn/model/impl/AbstractTDefinitions.java   |   2 +-
 .../dmn/model/impl/AbstractTDefinitionsTest.java   | 203 +++++++++++++++++++++
 2 files changed, 204 insertions(+), 1 deletion(-)

diff --git 
a/kie-dmn/kie-dmn-model/src/main/java/org/kie/dmn/model/impl/AbstractTDefinitions.java
 
b/kie-dmn/kie-dmn-model/src/main/java/org/kie/dmn/model/impl/AbstractTDefinitions.java
index b4e7a7d240..c5c6c31de0 100644
--- 
a/kie-dmn/kie-dmn-model/src/main/java/org/kie/dmn/model/impl/AbstractTDefinitions.java
+++ 
b/kie-dmn/kie-dmn-model/src/main/java/org/kie/dmn/model/impl/AbstractTDefinitions.java
@@ -149,6 +149,6 @@ public abstract class AbstractTDefinitions extends 
AbstractTNamedElement impleme
      */
     @Override
     public List<DecisionService> getDecisionService() {
-        return 
drgElement.stream().filter(DecisionService.class::isInstance).map(DecisionService.class::cast).collect(Collectors.toList());
+        return 
getDrgElement().stream().filter(DecisionService.class::isInstance).map(DecisionService.class::cast).collect(Collectors.toList());
     }
 }
diff --git 
a/kie-dmn/kie-dmn-model/src/test/java/org/kie/dmn/model/impl/AbstractTDefinitionsTest.java
 
b/kie-dmn/kie-dmn-model/src/test/java/org/kie/dmn/model/impl/AbstractTDefinitionsTest.java
new file mode 100644
index 0000000000..e5bfa55c06
--- /dev/null
+++ 
b/kie-dmn/kie-dmn-model/src/test/java/org/kie/dmn/model/impl/AbstractTDefinitionsTest.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.model.impl;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.model.api.Artifact;
+import org.kie.dmn.model.api.BusinessContextElement;
+import org.kie.dmn.model.api.DRGElement;
+import org.kie.dmn.model.api.DecisionService;
+import org.kie.dmn.model.api.Definitions;
+import org.kie.dmn.model.api.ElementCollection;
+import org.kie.dmn.model.api.Import;
+import org.kie.dmn.model.api.ItemDefinition;
+import org.kie.dmn.model.v1_6.TDecision;
+import org.kie.dmn.model.v1_6.TDecisionService;
+import org.kie.dmn.model.v1_6.TDefinitions;
+import org.kie.dmn.model.v1_6.TImport;
+import org.kie.dmn.model.v1_6.TItemDefinition;
+import org.kie.dmn.model.v1_6.TTextAnnotation;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class AbstractTDefinitionsTest {
+
+    @Test
+    void getImportInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<Import> imports = definitions.getImport();
+        
+        assertThat(imports).isNotNull();
+        assertThat(imports).isEmpty();
+    }
+
+    @Test
+    void getImportAllowsAddingElements() {
+        Definitions definitions = new TDefinitions();
+        
+        Import import1 = new TImport();
+        import1.setNamespace("http://example.com/ns1";);
+        definitions.getImport().add(import1);
+        
+        assertThat(definitions.getImport()).hasSize(1);
+        assertThat(definitions.getImport()).contains(import1);
+    }
+
+    @Test
+    void getItemDefinitionInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<ItemDefinition> itemDefinitions = definitions.getItemDefinition();
+        
+        assertThat(itemDefinitions).isNotNull();
+        assertThat(itemDefinitions).isEmpty();
+    }
+
+    @Test
+    void getItemDefinitionAllowsAddingElements() {
+        Definitions definitions = new TDefinitions();
+        
+        ItemDefinition item = new TItemDefinition();
+        item.setName("CustomType");
+        definitions.getItemDefinition().add(item);
+        
+        assertThat(definitions.getItemDefinition()).hasSize(1);
+        assertThat(definitions.getItemDefinition()).contains(item);
+    }
+
+    @Test
+    void getDrgElementInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<DRGElement> drgElements = definitions.getDrgElement();
+        
+        assertThat(drgElements).isNotNull();
+        assertThat(drgElements).isEmpty();
+    }
+
+    @Test
+    void getDrgElementAllowsAddingElements() {
+        Definitions definitions = new TDefinitions();
+        
+        DRGElement decision = new TDecision();
+        decision.setName("Decision1");
+        definitions.getDrgElement().add(decision);
+        
+        assertThat(definitions.getDrgElement()).hasSize(1);
+        assertThat(definitions.getDrgElement()).contains(decision);
+    }
+
+    @Test
+    void getArtifactInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<Artifact> artifacts = definitions.getArtifact();
+        
+        assertThat(artifacts).isNotNull();
+        assertThat(artifacts).isEmpty();
+    }
+
+    @Test
+    void getArtifactAllowsAddingElements() {
+        Definitions definitions = new TDefinitions();
+        
+        TTextAnnotation annotation = new TTextAnnotation();
+        annotation.setText("Test annotation");
+        definitions.getArtifact().add(annotation);
+        
+        assertThat(definitions.getArtifact()).hasSize(1);
+        assertThat(definitions.getArtifact()).contains(annotation);
+    }
+
+    @Test
+    void getElementCollectionInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<ElementCollection> collections = 
definitions.getElementCollection();
+        
+        assertThat(collections).isNotNull();
+        assertThat(collections).isEmpty();
+    }
+
+    @Test
+    void getBusinessContextElementInitializesListWhenNull() {
+        Definitions definitions = new TDefinitions();
+        
+        List<BusinessContextElement> elements = 
definitions.getBusinessContextElement();
+        
+        assertThat(elements).isNotNull();
+        assertThat(elements).isEmpty();
+    }
+
+    @Test
+    void getDecisionServiceWithNullDrgElement() {
+        Definitions definitions = new TDefinitions();
+        
+        List<DecisionService> decisionServices = 
definitions.getDecisionService();
+        
+        assertThat(decisionServices).isNotNull();
+        assertThat(decisionServices).isEmpty();
+    }
+
+    @Test
+    void getDecisionServiceWithDecisionServices() {
+        Definitions definitions = new TDefinitions();
+        
+        DecisionService decisionService1 = new TDecisionService();
+        decisionService1.setName("Service1");
+        definitions.getDrgElement().add(decisionService1);
+        
+        DecisionService decisionService2 = new TDecisionService();
+        decisionService2.setName("Service2");
+        definitions.getDrgElement().add(decisionService2);
+        
+        List<DecisionService> decisionServices = 
definitions.getDecisionService();
+        
+        assertThat(decisionServices).isNotNull();
+        assertThat(decisionServices).hasSize(2);
+        assertThat(decisionServices).containsExactly(decisionService1, 
decisionService2);
+    }
+
+    @Test
+    void getDecisionServiceWithMixedDrgElements() {
+        Definitions definitions = new TDefinitions();
+        
+        DecisionService decisionService = new TDecisionService();
+        decisionService.setName("Service1");
+        definitions.getDrgElement().add(decisionService);
+        
+        // Add other DRGElement types (TDecision is not a DecisionService)
+        DRGElement decision = new TDecision();
+        decision.setName("Decision1");
+        definitions.getDrgElement().add(decision);
+        
+        DecisionService decisionService2 = new TDecisionService();
+        decisionService2.setName("Service2");
+        definitions.getDrgElement().add(decisionService2);
+        
+        List<DecisionService> decisionServices = 
definitions.getDecisionService();
+        
+        assertThat(decisionServices).isNotNull();
+        assertThat(decisionServices).hasSize(2);
+        assertThat(decisionServices).containsExactly(decisionService, 
decisionService2);
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to