From 8842b2b8c556a88a6820e92e4c4f677b585b7f19 Mon Sep 17 00:00:00 2001 From: maximthomas Date: Mon, 15 Aug 2022 15:27:20 +0300 Subject: [PATCH] Fix recursive load guava cache error --- .../InMemoryInternalSessionCacheStep.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/openam-core/src/main/java/org/forgerock/openam/session/service/access/persistence/caching/InMemoryInternalSessionCacheStep.java b/openam-core/src/main/java/org/forgerock/openam/session/service/access/persistence/caching/InMemoryInternalSessionCacheStep.java index 3863d65693..60b0e01c74 100644 --- a/openam-core/src/main/java/org/forgerock/openam/session/service/access/persistence/caching/InMemoryInternalSessionCacheStep.java +++ b/openam-core/src/main/java/org/forgerock/openam/session/service/access/persistence/caching/InMemoryInternalSessionCacheStep.java @@ -193,25 +193,25 @@ long size() { private InternalSession getFromCacheOrFind(final String key, final Callable sessionFinder) throws SessionPersistenceException { try { - return getCache().get(key, new Callable() { - @Override - public InternalSession call() throws Exception { - InternalSession result = sessionFinder.call(); - if (result == null) { - throw NullResultException.INSTANCE; - } - return result; + InternalSession internalSession = getCache().getIfPresent(key); + if(internalSession == null) { + internalSession = sessionFinder.call(); + if (internalSession == null) { + throw NullResultException.INSTANCE; } - }); - } catch (ExecutionException e) { - if (e.getCause() instanceof NullResultException) { + } + getCache().put(key, internalSession); + return internalSession; + + } catch (Exception e) { + if (e instanceof NullResultException) { // There was no result - return back into a null here return null; } // Rethrow any Error/RuntimeException/SessionPersistenceException - Throwables.propagateIfPossible(e.getCause(), SessionPersistenceException.class); + Throwables.propagateIfPossible(e, SessionPersistenceException.class); // Wrap anything else as a new SessionPersistenceException - throw new SessionPersistenceException(e.getMessage(), e.getCause()); + throw new SessionPersistenceException(e.getMessage(), e); } }