From b14041aa3a816e709511519fbb746ede93218ab4 Mon Sep 17 00:00:00 2001 From: bzp99 Date: Sun, 30 Jul 2023 13:19:35 +0200 Subject: [PATCH] Refactor piece of code that causes stack overflow --- .../java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java index 819aab8..dc0391a 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java @@ -1199,6 +1199,7 @@ private DeliveredOrder getOldestNewOrderForDistrict( final List matchingNewOrders = registry .select(ctx, new NewOrder()) + /* TODO this code causes a StackOverflowError for some reason .matching( new Registry.Matcher() { @Override @@ -1206,6 +1207,7 @@ public boolean match(NewOrder entity) { return entity.getNo_w_id() == w_id && entity.getNo_d_id() == d_id; } }) + */ .sortedBy( new Comparator() { @Override @@ -1214,6 +1216,14 @@ public int compare(final NewOrder a, final NewOrder b) { } }) .get(); + /* Manually remove non-matching NewOrders, see above... */ + final Iterator it = matchingNewOrders.iterator(); + while (it.hasNext()) { + final NewOrder no = it.next(); + if (no.getNo_w_id() != w_id || no.getNo_d_id() != d_id) it.remove(); + } + logger.debug("matchingNewOrders={}", matchingNewOrders); + /* * [TPC-C 2.7.4.2 (3) (continued)] * ... If no matching row is found, then the delivery of an order