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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.7
    • None
    • Engine
    • 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);
      }

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: