diff --git a/src/main/java/com/hubspot/jinjava/interpret/Context.java b/src/main/java/com/hubspot/jinjava/interpret/Context.java index 537d998dc..61b3c5eda 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/Context.java +++ b/src/main/java/com/hubspot/jinjava/interpret/Context.java @@ -407,15 +407,18 @@ public void checkNumberOfDeferredTokens() { secondToLastContext = secondToLastContext.parent; } } - int maxNumDeferredTokens = JinjavaInterpreter + int currentNumDeferredTokens = secondToLastContext.deferredTokens.size(); + JinjavaInterpreter .getCurrentMaybe() .map(i -> i.getConfig().getMaxNumDeferredTokens()) - .orElse(1000); - if (secondToLastContext.deferredTokens.size() >= maxNumDeferredTokens) { - throw new DeferredValueException( - "Too many Deferred Tokens, max is " + maxNumDeferredTokens + .filter(maxNumDeferredTokens -> currentNumDeferredTokens >= maxNumDeferredTokens) + .ifPresent( + maxNumDeferredTokens -> { + throw new DeferredValueException( + "Too many Deferred Tokens, max is " + maxNumDeferredTokens + ); + } ); - } } @Beta