Velocity
  1. Velocity
  2. VELOCITY-673

Remove calling init method from the VelocityEngine non default constructors

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      None

      Description

      Based on the following user group discussion:

      On Jan 19, 2009, at 13:44 , lacco wrote:

      Okay, it works now: The init method shouldn't be called at all when setting
      properties by hand... Besides, the servlet context has to be set. My final version:

      VelocityEngine ve = new VelocityEngine();
      ve.setApplicationAttribute("javax.servlet.ServletContext",
      servletContext);
      ve.setProperty("resource.loader", "webapp");
      ve.setProperty("webapp.resource.loader.class",
      "org.apache.velocity.tools.view.servlet.WebappLoader");
      ve.setProperty("webapp.resource.loader.path",
      "/WEB-INF/classes/de/hpi/petrinet/serialization/erdf");
      Template t = ve.getTemplate( "petrinet.erdf.vm" );

      On Mon, Jan 19, 2009 at 11:12 PM, Byron Foster <byron@base2.cc> wrote:

      Yea, I think this is confusing. Calling the non default constructors for
      VelocityEngine calls the init() method, but calling the default constructor
      does not. So, if you call VelocityEngine(props) then you can't set any more
      properties after that point.

      Nathan responded:

      Agreed. Let's change that. Besides, most methods that need Velocity
      to be init'ed will now call it themselves if used before init() has
      been called. There is absolutely no reason to call init from any
      constructor.

        Activity

        Hide
        Byron Foster added a comment -

        This also fixes an initialization race condition when using the default VelocityEngine constructor (and now non default constructors) and two threads attempt to call RuntimeInstance.getTemplate at the same time with no prior RuntimeInstance.init call. This would also affect using the Velocity.java API.

        Show
        Byron Foster added a comment - This also fixes an initialization race condition when using the default VelocityEngine constructor (and now non default constructors) and two threads attempt to call RuntimeInstance.getTemplate at the same time with no prior RuntimeInstance.init call. This would also affect using the Velocity.java API.

          People

          • Assignee:
            Unassigned
            Reporter:
            Byron Foster
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development