Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-809

RuntimeInstance returns template with incorrect encoding (if not specified) when not initialized before

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      None

      Description

      RuntimeInstance has

      public Template getTemplate(String name)
      throws ResourceNotFoundException, ParseErrorException
      {
      return getTemplate(name, getDefaultEncoding());
      }

      so if RuntimeInstance was not initialized before this method was called then it provides default encoding (ENCODING_DEFAULT = "ISO-8859-1") for getDefaultEncoding() instead of those that was set using

      .setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8")

      and Template contents incorrectly loaded.

      This is so because initialization is done one step after a call of getDefaultEncoding() inside method

      public Template getTemplate(String name, String encoding)
      throws ResourceNotFoundException, ParseErrorException
      {
      requireInitialization();

      return (Template)
      resourceManager.getResource(name,
      ResourceManager.RESOURCE_TEMPLATE, encoding);
      }

      Solution is to add requireInitialization(); before return getTemplate(name, getDefaultEncoding()); line in the first method.
      OR
      accept encoding == null in the second method:

      public Template getTemplate(String name)
      throws ResourceNotFoundException, ParseErrorException
      {
      return getTemplate(name, null);
      }

      public Template getTemplate(String name, String encoding)
      throws ResourceNotFoundException, ParseErrorException
      {
      requireInitialization();

      if (encoding == null)
      encoding = getDefaultEncoding();

      return (Template)
      resourceManager.getResource(name,
      ResourceManager.RESOURCE_TEMPLATE, encoding);
      }

        Activity

        Hide
        claude Claude Brisson added a comment -

        Fixed by commit 1752790.

        Show
        claude Claude Brisson added a comment - Fixed by commit 1752790.

          People

          • Assignee:
            Unassigned
            Reporter:
            darkmortal Dark Mortal
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development