Skip to content

Commit 02ce35d

Browse files
willr3stalep
authored andcommitted
fix npe from calculateSourceValuePermutations
1 parent a869159 commit 02ce35d

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/main/java/io/hyperfoil/tools/h5m/svc/NodeService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public List<Map<String, ValueEntity>> calculateSourceValuePermutations(NodeEntit
247247
}else if(nValues.size()>idx){
248248
sourceValuesAtIndex.put(n.name,nValues.get(idx));
249249
}else{
250-
return null;
250+
//do nothing with a missing value
251251
}
252252
}
253253
rtrn.add(sourceValuesAtIndex);

src/test/java/io/hyperfoil/tools/h5m/svc/NodeServiceTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.hyperfoil.tools.h5m.svc;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import com.fasterxml.jackson.databind.JsonNode;
45
import com.fasterxml.jackson.databind.ObjectMapper;
56
import com.fasterxml.jackson.databind.node.DoubleNode;
@@ -21,6 +22,7 @@
2122
import java.io.IOException;
2223
import java.nio.file.Files;
2324
import java.util.*;
25+
import java.util.stream.Collectors;
2426
import java.util.stream.Stream;
2527

2628
import static io.hyperfoil.tools.h5m.entity.NodeEntity.FQDN_SEPARATOR;
@@ -582,6 +584,54 @@ public void calculateJqValues_multiple_sourceValues() throws IOException, Heuris
582584
assertTrue(read.startsWith("["),"value should be an array: "+read);
583585
assertTrue(read.endsWith("]"),"value should be an array: "+read);
584586
}
587+
@Test
588+
public void calculateSourceValuePermutations_returns_non_null_on_length_mismatch() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException, JsonProcessingException {
589+
tm.begin();
590+
NodeEntity root = new RootNode();
591+
root.persist();
592+
593+
// Create two source nodes that will produce different numbers of values
594+
NodeEntity firstNode = new JqNode("first","$.first[]",root);
595+
firstNode.persist();
596+
NodeEntity secondNode = new JqNode("second","$.second[]",root);
597+
secondNode.persist();
598+
599+
// Create a combined node with Length multiType (default) and two sources
600+
NodeEntity combined = new JsNode("combined","obj=>Object.values(obj)", List.of(firstNode, secondNode));
601+
combined.multiType = NodeEntity.MultiIterationType.Length; // Explicitly set to Length
602+
combined.persist();
603+
604+
// Root value with arrays of different lengths
605+
ValueEntity rootValue = new ValueEntity(null, root, new ObjectMapper().readTree("""
606+
{
607+
"first": [1, 2, 3]
608+
}
609+
"""));
610+
rootValue.persist();
611+
612+
// First node produces 3 values
613+
ValueEntity firstValue1 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("1"));
614+
firstValue1.idx=1;
615+
firstValue1.sources=List.of(rootValue);
616+
firstValue1.persist();
617+
ValueEntity firstValue2 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("2"));
618+
firstValue2.idx=2;
619+
firstValue2.sources=List.of(rootValue);
620+
firstValue2.persist();
621+
ValueEntity firstValue3 = new ValueEntity(null, firstNode, new ObjectMapper().readTree("3"));
622+
firstValue3.idx=3;
623+
firstValue3.sources=List.of(rootValue);
624+
firstValue3.persist();
625+
626+
tm.commit();
627+
628+
// When multiType is Length and source nodes have mismatched value counts,
629+
// calculateSourceValuePermutations should return null
630+
List<Map<String, ValueEntity>> result = nodeService.calculateSourceValuePermutations(combined, rootValue);
631+
632+
assertNotNull(result, "Expected not-null when Length multiType has mismatched source value counts:");
633+
}
634+
585635
@Test
586636
public void calculateJqValues_multiple_source_order() throws IOException, HeuristicRollbackException, SystemException, HeuristicMixedException, RollbackException, NotSupportedException {
587637
tm.begin();

0 commit comments

Comments
 (0)