Skip to content

Bug introduced in 2.7.3 - Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently #1212

Closed

Description

@sjanel

Hello,

Our code uses latest version 2.7.3 of Jinjava. There is a new field, in Context object, that makes it impossible to share across different threads, causing exceptions when the interpreter render method is called:

Caused by: com.hubspot.jinjava.interpret.InterpretException: Error rendering tag
	at com.hubspot.jinjava.tree.TagNode.render(TagNode.java:74)
	at com.hubspot.jinjava.interpret.JinjavaInterpreter.render(JinjavaInterpreter.java:363)
	at com.hubspot.jinjava.interpret.JinjavaInterpreter.render(JinjavaInterpreter.java:307)
	at ...
Caused by: java.util.ConcurrentModificationException: null
	at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1605)
	at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1628)
	at java.base/java.util.AbstractSet.removeAll(AbstractSet.java:175)
	at com.hubspot.jinjava.interpret.Context.removeNonMetaContextVariables(Context.java:368)
	at com.hubspot.jinjava.lib.tag.ForTag.renderForCollection(ForTag.java:292)
	at com.hubspot.jinjava.lib.tag.ForTag.interpretUnchecked(ForTag.java:155)
	at com.hubspot.jinjava.lib.tag.ForTag.interpret(ForTag.java:120)
	at com.hubspot.jinjava.lib.tag.Tag.interpretOutput(Tag.java:27)
	at com.hubspot.jinjava.tree.TagNode.render(TagNode.java:58)
	... 49 common frames omitted

I think that the field overriddenNonMetaContextVariables should allow concurrent access, otherwise client code needs to explicitly synchronize calls to render for a single top level context which holds this unique instance of this HashMap for a whole tree, which is not ideal:

this.overriddenNonMetaContextVariables =
      parent == null ? new HashSet<>() : parent.overriddenNonMetaContextVariables;

There is no issue if we revert to 2.7.2 version.

Activity

  1. changed the title [-]Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently[/-] [+]Bug introduced in 2.7.3 - Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently[/+] on Oct 18, 2024
  2. sjanel commented on Jan 27, 2025

    @sjanel
    Author

    Hello, any news for this ?

  3. sjanel commented on Apr 24, 2025

    @sjanel
    Author

    Hello ?

  4. jasmith-hs commented on Apr 24, 2025

    @jasmith-hs
    Contributor

    @sjanel , fixing with #1239. This functionality shouldn't be present in the default Jinjava tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions