From 82344de953e2be11b2b0a1a7e6039c43c245fbaf Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Mon, 19 Jun 2023 16:16:45 +0200 Subject: [PATCH] Fix null pointer exception --- .../org/apache/baremaps/tilestore/TileCache.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCache.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCache.java index 036107678..6e0377907 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCache.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCache.java @@ -51,19 +51,19 @@ public TileCache(TileStore tileStore, CaffeineSpec spec) { /** {@inheritDoc} */ @Override public ByteBuffer read(TileCoord tileCoord) throws TileStoreException { - return cache.get(tileCoord, t -> { + var buffer = cache.get(tileCoord, t -> { try { - var buffer = tileStore.read(t); - if (buffer == null) { - return null; - } else { - return buffer; - } + return tileStore.read(t); } catch (TileStoreException e) { logger.error("Unable to read the tile.", e); return null; } - }).duplicate(); + }); + if (buffer == null) { + return null; + } else { + return buffer.duplicate(); + } } /** {@inheritDoc} */