Avoid NoSuchElementException "No value present" When parsing the response from Cache#getIfPresent we end up in states where EiffelEventIdCache#getEventIdIfPresent throws NoSuchElementException. Rewrite the conversion from @Nullable Optional<UUID> to Optional<UUID> to be more clear to avoid this or at least get a clear indication of exactly what happens. Solves: Jira GER-1612 Change-Id: I3668c29aa284674a0cf8e36be80162f4d1bf71eb
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/cache/EiffelEventIdCacheImpl.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/cache/EiffelEventIdCacheImpl.java index 3bc237d..5377521 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/cache/EiffelEventIdCacheImpl.java +++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/cache/EiffelEventIdCacheImpl.java
@@ -94,7 +94,11 @@ } private Optional<UUID> getEventIdIfPresent(EventKey key) { - return Optional.ofNullable(eventIds.getIfPresent(key)).map(Optional::get); + Optional<UUID> fromCache = eventIds.getIfPresent(key); + if (fromCache == null) { + return Optional.empty(); + } + return fromCache; } @Override