Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-3811

FreemarkerConfig sharedVariables doesn't play well with content2bean

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 4.4.5
    • 4.4.4
    • core, freemarker
    • None

      In some cases, FreemarkerConfig's sharedVariables aren't populated properly by content2bean. It seems to be due to the order of methods (which can be lost/changed when hot deploying classes, for example).

      FreemarkerConfig has two addSharedVariable methods, one of which takes an Object value (which is what c2b should use) and one which takes a Template model instance (which could be used in cases where we have a pre-wrapped object we want to expose).

      This was done as a result of mistakenly thinking c2b would pick the most appropriate method, depending on the arguments (i.e like Java does naturally with method overloading). However, it's not the case: when looking for "add" methods, Content2bean uses the first one it finds with a matching name. In this case, and when source code order was preserved, it finds and uses (addSharedVariable(String name, Object value) and everything's peachy.

      Obviously this highly depends on the order of the methods, i.e depends on how the code was compiled. In most cases, it seems the source order is kept, but probably when hot deploying classes, this order can change. As a result, c2b sometimes uses the addSharedVariable(String name, TemplateModel value method, which results in a reflection exception (arguments mismatch).

      This has already been fixed on the trunk for 4.5 with SCRUM-30, so we'll apply the same fix on the 4.4 branch, simply removing the addSharedVariable(String name, TemplateModel value, which never worked.

        Acceptance criteria

              gjoseph Magnolia International
              gjoseph Magnolia International
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD