Skip to content

Commit 7adb6cb

Browse files
jasmith-hsclaude
andcommitted
Address further Sidekick review feedback
- Use instanceof pattern matching in NoInvokeELContext to avoid bare ClassCastException when delegate doesn't implement HasInterpreter - Guard against null JinjavaInterpreter.getCurrent() in SizeLimitingPySet.checkSize Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 88eb7dc commit 7adb6cb

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/main/java/com/hubspot/jinjava/el/NoInvokeELContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public VariableMapper getVariableMapper() {
3535

3636
@Override
3737
public JinjavaInterpreter interpreter() {
38-
return ((HasInterpreter) delegate).interpreter();
38+
if (delegate instanceof HasInterpreter hasInterpreter) {
39+
return hasInterpreter.interpreter();
40+
}
41+
return JinjavaInterpreter.getCurrent();
3942
}
4043
}

src/main/java/com/hubspot/jinjava/objects/collections/SizeLimitingPySet.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ private void checkSize(int newSize) {
5050
throw new CollectionTooBigException(newSize, maxSize);
5151
} else if (!hasWarned && newSize >= maxSize * 0.9) {
5252
hasWarned = true;
53-
JinjavaInterpreter
54-
.getCurrent()
55-
.addError(
53+
JinjavaInterpreter current = JinjavaInterpreter.getCurrent();
54+
if (current == null) {
55+
return;
56+
}
57+
current.addError(
5658
new TemplateError(
5759
ErrorType.WARNING,
5860
ErrorReason.COLLECTION_TOO_BIG,

0 commit comments

Comments
 (0)