Velocity
  1. Velocity
  2. VELOCITY-688

! preceding a reference in strict mode ignores a null exception

    Details

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

      Description

      Change strict mode (runtime.references.strict = true) behavior such that when Velocity attempts to render a reference that evaluates to null then throw an exception. If the reference is preceded by '$!' as in $!foo, then simply render nothing and ignore the null value as it does for non strict mode.

        Activity

        Hide
        Byron Foster added a comment -

        Changed the orientation of this feature so that a null value renders nothing when the variable is preceded with '$', but will throw an exception when preceded with "$!".

        Show
        Byron Foster added a comment - Changed the orientation of this feature so that a null value renders nothing when the variable is preceded with '$', but will throw an exception when preceded with "$!".
        Hide
        Nathan Bubna added a comment -

        Huh? I don't get it. Why should null be allowed when using normal syntax but dis-allowed when using quiet syntax. That seems opposite of what it should be. Am i missing something here?

        Show
        Nathan Bubna added a comment - Huh? I don't get it. Why should null be allowed when using normal syntax but dis-allowed when using quiet syntax. That seems opposite of what it should be. Am i missing something here?
        Hide
        Byron Foster added a comment -

        Well, I figure rendering $foo as a blank string when it is null is the more natural thing to do, and the behavior that in most cases will be desired. I Just made it so that if people really want an exception thrown when $foo is equal to null, they could use the bang syntax ($!foo). But, this is more just using an existing syntax mechanism more then anything else. I could just as easily in strict mode go with the bang not doing anything at all, I don't think it's really needed. Not sure, thoughts?

        Show
        Byron Foster added a comment - Well, I figure rendering $foo as a blank string when it is null is the more natural thing to do, and the behavior that in most cases will be desired. I Just made it so that if people really want an exception thrown when $foo is equal to null, they could use the bang syntax ($!foo). But, this is more just using an existing syntax mechanism more then anything else. I could just as easily in strict mode go with the bang not doing anything at all, I don't think it's really needed. Not sure, thoughts?
        Hide
        Nathan Bubna added a comment -

        Natural is all relative. I guess i can understand strict ref rendering $foo as empty string, because in strict ref mode $foo is never schmoo. But using $! to say "go boom when null" seems really unnatural to me as a Velocity user who is used to $! meaning "this can be null".

        Honestly, i think it would make more sense to have $foo throw an exception when undefined or null and have $!foo still throw an exception when undefined but render empty string when null. Which, i think is how it was, right?

        Show
        Nathan Bubna added a comment - Natural is all relative. I guess i can understand strict ref rendering $foo as empty string, because in strict ref mode $foo is never schmoo. But using $! to say "go boom when null" seems really unnatural to me as a Velocity user who is used to $! meaning "this can be null". Honestly, i think it would make more sense to have $foo throw an exception when undefined or null and have $!foo still throw an exception when undefined but render empty string when null. Which, i think is how it was, right?
        Hide
        Christoph Reck added a comment - - edited

        The original intent of the bang syntax ($!foo) - it is to allow the template writer to say "this may be null".

        Without strict mode, $!foo will not log anything if it is undefined or null.

        I have not used the strict mode, so I have not considered what to do then for a $foo that is undefined or null. I do agree with Nathan that a $foo null reference in strict mode should throw an exception as originally devised. A $!foo null reference in strict mode could output nothing or throw an exception (no preference here).

        Show
        Christoph Reck added a comment - - edited The original intent of the bang syntax ($!foo) - it is to allow the template writer to say "this may be null". Without strict mode, $!foo will not log anything if it is undefined or null. I have not used the strict mode, so I have not considered what to do then for a $foo that is undefined or null. I do agree with Nathan that a $foo null reference in strict mode should throw an exception as originally devised. A $!foo null reference in strict mode could output nothing or throw an exception (no preference here).
        Hide
        Byron Foster added a comment -

        Nathan, the answer to your question is yes

        Ok, sounds fair. I'v changed the behavior back to the original behavior of this issue, i.e., if $foo is null an exception is thrown, if $!foo is null, then render nothing.

        Anyway, the prior behavior can always be achieved by adding an insertReference handler that handles nulls.

        Show
        Byron Foster added a comment - Nathan, the answer to your question is yes Ok, sounds fair. I'v changed the behavior back to the original behavior of this issue, i.e., if $foo is null an exception is thrown, if $!foo is null, then render nothing. Anyway, the prior behavior can always be achieved by adding an insertReference handler that handles nulls.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development