From a0d870b3b65196d7e70c380ef7b7101281caaa9c Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 14 Oct 2024 12:18:28 -0500 Subject: [PATCH] Prevent NPE for nested include files with no featureManager element --- .../common/plugins/util/ServerFeatureUtil.java | 2 +- ...nstallFeatureUtilGetServerFeaturesTest.java | 18 ++++++++++++++++++ .../servers/noList_nested_features.xml | 4 ++++ .../resources/servers/server_merge_nested.xml | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/servers/noList_nested_features.xml create mode 100644 src/test/resources/servers/server_merge_nested.xml diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/ServerFeatureUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/ServerFeatureUtil.java index fc0d23ad..6bf78e40 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/ServerFeatureUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/ServerFeatureUtil.java @@ -612,7 +612,7 @@ private FeaturesPlatforms handleOnConflict(FeaturesPlatforms origResult, String } else { // anything else counts as "merge", even if the onConflict value is invalid if ((fp != null) && (!fp.getFeatures().isEmpty() || !fp.getPlatforms().isEmpty())) { - if (result.getFeatures().isEmpty() && result.getPlatforms().isEmpty()) { + if ((result == null) || (result.getFeatures().isEmpty() && result.getPlatforms().isEmpty())) { result = fp; } else { result.getFeatures().addAll(fp.getFeatures()); diff --git a/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilGetServerFeaturesTest.java b/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilGetServerFeaturesTest.java index 41dd610e..b8ffd60d 100644 --- a/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilGetServerFeaturesTest.java +++ b/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilGetServerFeaturesTest.java @@ -156,6 +156,24 @@ public void testMergeServerXML() throws Exception{ verifyServerFeatures(expected); } + /** + * Tests server.xml with MERGE function with nested include files, one of which contains no featureManager + * + * @throws Exception + */ + @Test + public void testNestedMergeServerXML() throws Exception{ + copyAsName("server_merge_nested.xml", "server.xml"); + copy("extraFeatures.xml"); + copy("noList_nested_features.xml"); + + Set expected = new HashSet(); + expected.add("orig"); + expected.add("extra"); + + verifyServerFeatures(expected); + } + /** * Tests server.xml with REPLACE function * diff --git a/src/test/resources/servers/noList_nested_features.xml b/src/test/resources/servers/noList_nested_features.xml new file mode 100644 index 00000000..a11901c5 --- /dev/null +++ b/src/test/resources/servers/noList_nested_features.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/test/resources/servers/server_merge_nested.xml b/src/test/resources/servers/server_merge_nested.xml new file mode 100644 index 00000000..2a29f2b6 --- /dev/null +++ b/src/test/resources/servers/server_merge_nested.xml @@ -0,0 +1,7 @@ + + + + orig + + + \ No newline at end of file