This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch 2.1 in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push: new b5948f954c uses try w/ resources to close rfile block (#5381) b5948f954c is described below commit b5948f954c84d1d4bccb28db6c87fc3eeaf3a3f9 Author: Keith Turner <ktur...@apache.org> AuthorDate: Thu Mar 6 11:45:17 2025 -0500 uses try w/ resources to close rfile block (#5381) Code to read an rfile data block would close in a finally block. If close threw an IOException then any exception in the try block would be lost in the stack trace. Changed the code to use try w/ resources which has much better exception handling for this case. --- .../core/file/blockfile/impl/CachableBlockFile.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/CachableBlockFile.java b/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/CachableBlockFile.java index a0ff32a703..d33f3d1bb6 100644 --- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/CachableBlockFile.java +++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/CachableBlockFile.java @@ -50,6 +50,8 @@ import org.slf4j.LoggerFactory; import com.google.common.cache.Cache; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * This is a wrapper class for BCFile that includes a cache for independent caches for datablocks * and metadatablocks @@ -337,6 +339,8 @@ public class CachableBlockFile { return Collections.emptyMap(); } + @SuppressFBWarnings(value = {"NP_LOAD_OF_KNOWN_NULL_VALUE"}, + justification = "Spotbugs false positive, see spotbugs issue 2836.") @Override public byte[] load(int maxSize, Map<String,byte[]> dependencies) { @@ -351,23 +355,18 @@ public class CachableBlockFile { } } - BlockReader _currBlock = getBlockReader(maxSize, reader); - if (_currBlock == null) { - return null; - } + try (BlockReader _currBlock = getBlockReader(maxSize, reader)) { + if (_currBlock == null) { + return null; + } - byte[] b = null; - try { - b = new byte[(int) _currBlock.getRawSize()]; + byte[] b = new byte[(int) _currBlock.getRawSize()]; _currBlock.readFully(b); + return b; } catch (IOException e) { log.debug("Error full blockRead for file " + cacheId + " for block " + getBlockId(), e); throw new UncheckedIOException(e); - } finally { - _currBlock.close(); } - - return b; } catch (IOException e) { throw new UncheckedIOException(e); }