From 234521b6512875bc1eb5316040e63387764c9b53 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sat, 28 Oct 2023 16:29:51 -0400 Subject: [PATCH] try/catch --- .../blockhash/BooleanBlockHash.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java index ee31a04d1e935..6f041a6681659 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/BooleanBlockHash.java @@ -75,28 +75,30 @@ private IntBlock add(BooleanBlock block) { @Override public BooleanBlock[] getKeys() { - BooleanBlock.Builder builder = blockFactory.newBooleanBlockBuilder(everSeen.length); - if (everSeen[NULL_ORD]) { - builder.appendNull(); - } - if (everSeen[FALSE_ORD]) { - builder.appendBoolean(false); - } - if (everSeen[TRUE_ORD]) { - builder.appendBoolean(true); + try (BooleanBlock.Builder builder = blockFactory.newBooleanBlockBuilder(everSeen.length)) { + if (everSeen[NULL_ORD]) { + builder.appendNull(); + } + if (everSeen[FALSE_ORD]) { + builder.appendBoolean(false); + } + if (everSeen[TRUE_ORD]) { + builder.appendBoolean(true); + } + return new BooleanBlock[] { builder.build() }; } - return new BooleanBlock[] { builder.build() }; } @Override public IntVector nonEmpty() { - IntVector.Builder builder = blockFactory.newIntVectorBuilder(everSeen.length); - for (int i = 0; i < everSeen.length; i++) { - if (everSeen[i]) { - builder.appendInt(i); + try (IntVector.Builder builder = blockFactory.newIntVectorBuilder(everSeen.length)) { + for (int i = 0; i < everSeen.length; i++) { + if (everSeen[i]) { + builder.appendInt(i); + } } + return builder.build(); } - return builder.build(); } public BitArray seenGroupIds(BigArrays bigArrays) {