diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java index 1cb336b87..f68188cba 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java @@ -1004,6 +1004,7 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward final GeckoResult result = new GeckoResult<>(); AtomicInteger count = new AtomicInteger(0); AtomicBoolean allowed = new AtomicBoolean(false); + final int listenerCount = mNavigationListeners.size() - 1; for (GeckoSession.NavigationDelegate listener: mNavigationListeners) { GeckoResult listenerResult = listener.onLoadRequest(aSession, aRequest); if (listenerResult != null) { @@ -1011,7 +1012,7 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward if (AllowOrDeny.ALLOW.equals(value)) { allowed.set(true); } - if (count.getAndIncrement() == mNavigationListeners.size() - 1) { + if (count.getAndIncrement() == listenerCount) { result.complete(allowed.get() ? AllowOrDeny.ALLOW : AllowOrDeny.DENY); } @@ -1020,7 +1021,7 @@ public void onCanGoForward(@NonNull GeckoSession aSession, boolean aCanGoForward } else { allowed.set(true); - if (count.getAndIncrement() == mNavigationListeners.size() - 1) { + if (count.getAndIncrement() == listenerCount) { result.complete(allowed.get() ? AllowOrDeny.ALLOW : AllowOrDeny.DENY); } }