java.lang.UnsupportedOperationException

Spring JIRA | Florent Robineau | 7 years ago
  1. 0

    Calls to VelocityEngineUtils.mergeTemplateIntoString using a Collections.singletonMap as the model fail with the following exception: java.lang.UnsupportedOperationException at java.util.AbstractMap.put(AbstractMap.java:186) at org.apache.velocity.VelocityContext.internalPut(VelocityContext.java:132) at org.apache.velocity.context.AbstractContext.put(AbstractContext.java:164) at org.apache.velocity.context.InternalContextAdapterImpl.put(InternalContextAdapterImpl.java:269) at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:213) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.Template.merge(Template.java:328) at org.apache.velocity.Template.merge(Template.java:235) at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:381) at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:345) at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58) at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122) ... Turns out that internally, Velocity tries to modify the map by calling methods that are not supported by the map implementation returned by Collections.singletonMap. I don't know if this should be considered a Spring issue, a Velocity issue, or a non-issue (but nothing in either Spring's or Velocity's docs warn against using immutable maps for the model). Possible fixes: - On Spring's side, create a new map containing the old map and pass it as the model, i.e. use "VelocityContext velocityContext = new VelocityContext(new HashMap(model));" in VelocityEngineUtils - Same thing, but on Velocity's side, when creating the VelocityContext - Leave to the user the responsibility to pass a mutable map, but mention it explicitly in the doc What do you think?

    Spring JIRA | 7 years ago | Florent Robineau
    java.lang.UnsupportedOperationException
  2. 0

    Calls to VelocityEngineUtils.mergeTemplateIntoString using a Collections.singletonMap as the model fail with the following exception: java.lang.UnsupportedOperationException at java.util.AbstractMap.put(AbstractMap.java:186) at org.apache.velocity.VelocityContext.internalPut(VelocityContext.java:132) at org.apache.velocity.context.AbstractContext.put(AbstractContext.java:164) at org.apache.velocity.context.InternalContextAdapterImpl.put(InternalContextAdapterImpl.java:269) at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:213) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.Template.merge(Template.java:328) at org.apache.velocity.Template.merge(Template.java:235) at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:381) at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:345) at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58) at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122) ... Turns out that internally, Velocity tries to modify the map by calling methods that are not supported by the map implementation returned by Collections.singletonMap. I don't know if this should be considered a Spring issue, a Velocity issue, or a non-issue (but nothing in either Spring's or Velocity's docs warn against using immutable maps for the model). Possible fixes: - On Spring's side, create a new map containing the old map and pass it as the model, i.e. use "VelocityContext velocityContext = new VelocityContext(new HashMap(model));" in VelocityEngineUtils - Same thing, but on Velocity's side, when creating the VelocityContext - Leave to the user the responsibility to pass a mutable map, but mention it explicitly in the doc What do you think?

    Spring JIRA | 7 years ago | Florent Robineau
    java.lang.UnsupportedOperationException
  3. 0

    Clazz parsing seems to have a problem with annotation

    GitHub | 3 years ago | pkriens
    java.lang.UnsupportedOperationException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Failed to retrieve Session from FacesContext

    Stack Overflow | 4 years ago | Stephan
    java.lang.UnsupportedOperationException
  6. 0

    Bug 205634 – UnsupportedOperationException at java.util.AbstractMap.put

    netbeans.org | 8 months ago
    java.lang.UnsupportedOperationException

    3 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.UnsupportedOperationException

      No message provided

      at java.util.AbstractMap.put()
    2. Java RT
      AbstractMap.put
      1. java.util.AbstractMap.put(AbstractMap.java:186)
      1 frame
    3. Apache Velocity
      VelocityEngine.mergeTemplate
      1. org.apache.velocity.VelocityContext.internalPut(VelocityContext.java:132)
      2. org.apache.velocity.context.AbstractContext.put(AbstractContext.java:164)
      3. org.apache.velocity.context.InternalContextAdapterImpl.put(InternalContextAdapterImpl.java:269)
      4. org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:213)
      5. org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
      6. org.apache.velocity.Template.merge(Template.java:328)
      7. org.apache.velocity.Template.merge(Template.java:235)
      8. org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:381)
      9. org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:345)
      9 frames
    4. Spring Context Support
      VelocityEngineUtils.mergeTemplateIntoString
      1. org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58)
      2. org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122)
      2 frames