Velocity
  1. Velocity
  2. VELOCITY-438

toString is called twice on references

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None

      Description

      ASTReference.java has some null check logic that does, summarized:

      if (value == null || value.toString() == null) {
      ...
      } else {
      ... output value.toString();
      }

      Note value.toString() being called twice.

      For strings and other primitives, this may not be a big deal, but I'm happily using Click, which puts full-fledged components into the velocity context that you render with "$componentName". Very slick. But now calling toString() multiple times isn't all that cool, both from perf and logic standpoints.

      I've got a patch if I can figure out how to upload it.

        Activity

        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551287 ] jira [ 12552008 ]
        Mark Thomas made changes -
        Workflow jira [ 12361197 ] Default workflow, editable Closed status [ 12551287 ]
        Henning Schmiedehausen made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Will Glass-Husain made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Will Glass-Husain added a comment -

        patched applied. sorry for the long delay. Thanks to Stephen for the patch (and Malcolm for the reminder

        Show
        Will Glass-Husain added a comment - patched applied. sorry for the long delay. Thanks to Stephen for the patch (and Malcolm for the reminder
        Hide
        Henning Schmiedehausen added a comment -

        Will commented that the patch is ok and he wants to put it in. Will? Did this fall through the cracks?

        Show
        Henning Schmiedehausen added a comment - Will commented that the patch is ok and he wants to put it in. Will? Did this fall through the cracks?
        Will Glass-Husain made changes -
        Fix Version/s 1.5 [ 12310253 ]
        Hide
        Will Glass-Husain added a comment -

        Thanks for the catch! I'll go ahead and commit this.

        Appreciate the unit test. Just as a quick side note, when submitting patches please remember to follow the Velocity coding convention for braces. I'll fix this when I commit.

        Show
        Will Glass-Husain added a comment - Thanks for the catch! I'll go ahead and commit this. Appreciate the unit test. Just as a quick side note, when submitting patches please remember to follow the Velocity coding convention for braces. I'll fix this when I commit.
        Stephen Haberman made changes -
        Field Original Value New Value
        Attachment call_tostring_only_once.txt [ 12325466 ]
        Hide
        Stephen Haberman added a comment -

        Patch ASTReference to not call value.toString() multiple times.

        Show
        Stephen Haberman added a comment - Patch ASTReference to not call value.toString() multiple times.
        Stephen Haberman created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Stephen Haberman
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development