Skip to content

Commit

Permalink
Prevent NPE for nested include files with no featureManager element
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Oct 14, 2024
1 parent a1c853f commit a0d870b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> expected = new HashSet<String>();
expected.add("orig");
expected.add("extra");

verifyServerFeatures(expected);
}

/**
* Tests server.xml with REPLACE function
*
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/servers/noList_nested_features.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<include location="extraFeatures.xml" onConflict="MERGE"/>
</server>
7 changes: 7 additions & 0 deletions src/test/resources/servers/server_merge_nested.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<featureManager>
<feature>orig</feature>
</featureManager>
<include location="noList_nested_features.xml" onConflict="MERGE"/>
</server>

0 comments on commit a0d870b

Please sign in to comment.