From 416228337a2b11cedd631de20938da2f7bb9f61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Fri, 5 Nov 2021 16:08:44 -0500 Subject: [PATCH] Avoid NPE on createBalanceCache. With zero `maxId`, and if there didn't exist a `BalanceCache`. The created `BalanceCache` has a null `balance`, which in turn triggered an NPE on `getBalance0`. --- modules/minigl/src/main/java/org/jpos/gl/GLSession.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/minigl/src/main/java/org/jpos/gl/GLSession.java b/modules/minigl/src/main/java/org/jpos/gl/GLSession.java index 577375f6b7..5b634cfe4a 100644 --- a/modules/minigl/src/main/java/org/jpos/gl/GLSession.java +++ b/modules/minigl/src/main/java/org/jpos/gl/GLSession.java @@ -1543,6 +1543,9 @@ private BalanceCache createFinalBalanceCache (Journal journal, FinalAccount acct c.setJournal (journal); c.setAccount (acct); c.setLayers (layersToString(layers)); + c.setBalance(ZERO); //Ensure we load a balance in the cache + //if maxId > 0 then the cache includes some entries, and + // we set the balance in the next if, before saving it. } if (maxId != c.getRef()) { c.setRef (maxId);