Skip to content

Commit 29792da

Browse files
jasmith-hsclaude
andcommitted
Handle missing interpreter in JinjavaBeanELResolver; add PySet to JinjavaObjects allowlist group
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6f943b0 commit 29792da

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/main/java/com/hubspot/jinjava/el/ext/AllowlistGroup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ String[] allowedDeclaredMethodsFromClasses() {
6868
private static final String[] ARRAY = {
6969
PyList.class.getCanonicalName(),
7070
PyMap.class.getCanonicalName(),
71+
PySet.class.getCanonicalName(),
7172
SizeLimitingPyMap.class.getCanonicalName(),
7273
SizeLimitingPyList.class.getCanonicalName(),
74+
SizeLimitingPySet.class.getCanonicalName(),
7375
SnakeCaseAccessibleMap.class.getCanonicalName(),
7476
FormattedDate.class.getCanonicalName(),
7577
PyishDate.class.getCanonicalName(),

src/main/java/com/hubspot/jinjava/el/ext/JinjavaBeanELResolver.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.base.CaseFormat;
44
import com.google.common.collect.ImmutableSet;
5-
import com.hubspot.jinjava.JinjavaConfig;
65
import com.hubspot.jinjava.interpret.DeferredValueException;
76
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
87
import com.hubspot.jinjava.util.EagerReconstructionUtils;
@@ -16,7 +15,6 @@
1615
import java.util.LinkedList;
1716
import java.util.List;
1817
import java.util.Map;
19-
import java.util.Objects;
2018
import java.util.Set;
2119
import java.util.concurrent.ConcurrentHashMap;
2220
import javax.el.ELContext;
@@ -222,30 +220,26 @@ protected Method findMethod(
222220
.orElseGet(() -> potentialMethods.stream().findAny().orElse(finalVarArgsMethod)
223221
);
224222
}
225-
return getJinjavaConfig().getMethodValidator().validateMethod(method);
223+
return getAllowlistMethodValidator().validateMethod(method);
226224
}
227225

228226
@Override
229227
protected Method getWriteMethod(Object base, Object property) {
230-
return getJinjavaConfig()
231-
.getMethodValidator()
228+
return getAllowlistMethodValidator()
232229
.validateMethod(super.getWriteMethod(base, property));
233230
}
234231

235232
@Override
236233
protected Method getReadMethod(Object base, Object property) {
237-
return getJinjavaConfig()
238-
.getMethodValidator()
234+
return getAllowlistMethodValidator()
239235
.validateMethod(super.getReadMethod(base, property));
240236
}
241237

242-
private static JinjavaConfig getJinjavaConfig() {
243-
return Objects
244-
.requireNonNull(
245-
JinjavaInterpreter.getCurrent(),
246-
"JinjavaInterpreter.closeablePushCurrent must be used if using a JinjavaBeanELResolver directly"
247-
)
248-
.getConfig();
238+
private static AllowlistMethodValidator getAllowlistMethodValidator() {
239+
return JinjavaInterpreter
240+
.getCurrentMaybe()
241+
.map(interpreter -> interpreter.getConfig().getMethodValidator())
242+
.orElse(AllowlistMethodValidator.DEFAULT);
249243
}
250244

251245
private static boolean checkAssignableParameterTypes(Object[] params, Method method) {

0 commit comments

Comments
 (0)