From 5cb64a5ffe00f3693a279fa25006e303bc9a44ce Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Wed, 17 Jun 2026 10:08:04 +0200 Subject: [PATCH] ST6RI-941 NPE when evaluating derived properties on feature chains Signed-off-by: Axel RICHARD --- .../java/org/omg/sysml/util/TypeUtil.java | 6 ++- .../org/omg/sysml/logic/TypeUtilTest.java | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 org.omg.sysml.logic/src/test/java/org/omg/sysml/logic/TypeUtilTest.java diff --git a/org.omg.sysml.logic/src/main/java/org/omg/sysml/util/TypeUtil.java b/org.omg.sysml.logic/src/main/java/org/omg/sysml/util/TypeUtil.java index bc2d20a6b..a24807567 100644 --- a/org.omg.sysml.logic/src/main/java/org/omg/sysml/util/TypeUtil.java +++ b/org.omg.sysml.logic/src/main/java/org/omg/sysml/util/TypeUtil.java @@ -1,7 +1,8 @@ /******************************************************************************* * SysML 2 Pilot Implementation * Copyright (c) 2021-2022, 2024-2026 Model Driven Solutions, Inc. - * + * Copyright (c) 2026 Obeo + * * This program is free software: you can redistribute it and/or modify * it under the terms of the Eclipse Public License as published by * the Eclipse Foundation, version 2 of the License. @@ -228,6 +229,9 @@ public static List getOwnedParametersOf(Type type) { if (type instanceof Feature) { type = FeatureUtil.getBasicFeatureOf((Feature)type); } + if (type == null) { + return new ArrayList<>(); + } return type.getOwnedFeature().stream(). filter(FeatureUtil::isParameter). collect(Collectors.toList()); diff --git a/org.omg.sysml.logic/src/test/java/org/omg/sysml/logic/TypeUtilTest.java b/org.omg.sysml.logic/src/test/java/org/omg/sysml/logic/TypeUtilTest.java new file mode 100644 index 000000000..c8d4559a2 --- /dev/null +++ b/org.omg.sysml.logic/src/test/java/org/omg/sysml/logic/TypeUtilTest.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * SysML 2 Pilot Implementation + * Copyright (c) 2026 Obeo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Eclipse Public License as published by + * the Eclipse Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Eclipse Public License for more details. + * + * You should have received a copy of theEclipse Public License + * along with this program. If not, see . + * + * @license EPL-2.0 + * + *******************************************************************************/ + +package org.omg.sysml.logic; + +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.omg.sysml.lang.sysml.AssignmentActionUsage; +import org.omg.sysml.lang.sysml.FeatureChaining; +import org.omg.sysml.lang.sysml.SysMLFactory; + +/** + * Tests utility behavior reached from SysML derived properties. + */ +public class TypeUtilTest { + + /** + * Derived properties on some feature-like SysML elements ask TypeUtil for + * owned parameters. When the feature is a chain whose target has not been + * linked yet, the basic feature is null and the derivation must simply see no + * parameters. + */ + @Test + public void derivedPropertyHandlesUnresolvedChainedFeatureWithoutParameters() { + SysMLLogicStandaloneSetup.doSetup(); + + AssignmentActionUsage assignment = SysMLFactory.eINSTANCE.createAssignmentActionUsage(); + FeatureChaining unresolvedChaining = SysMLFactory.eINSTANCE.createFeatureChaining(); + assignment.getOwnedRelationship().add(unresolvedChaining); + + assertNull(assignment.getValueExpression()); + } +}