You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2023/09/27 22:03:34 UTC
Calling static methods, revisited
All,
(This is all in the context of Velocity 1.7, but I'm not sure anything
has changed through 2.x.)
Sometimes you want to call a static method. Past workarounds are ugly
but get the job done. For example:
#set($string = "")
$string.format($locale, "format string", args)
I have a case where I've been working around java.util.TimeZone like this:
#set($tz = $dateIHave.timeZone)
#set($utc = $tx.getTimeZone('UTC'))
... use $utc
In recent versions of Java (I'm using Java 17 at the moment), I'm
getting this error:
Exception: org.apache.velocity.exception.VelocityException:
ASTMethod.execute() : exception invoking method 'getTimeZone' in class
sun.util.calendar.ZoneInfo
Stack Trace:
org.apache.velocity.exception.VelocityException: ASTMethod.execute() :
exception invoking method "getTimeZone" in class sun.util.calendar.ZoneInfo
org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:208)
...
I'm intending to call java.util.TimeZone.getTimeZone which should be
fine. But the runtime type of $tz ends up being
sun.util.calendar.ZoneInfo which, unfortunately, defines its own static
getTimeZone method whose signature matches that of java.util.TimeZone
but is not callable due to module.
In this case, is it possible for me to make a call to
java.util.TimeZone.getTimeZone, or is it time to write a new Tool or
customize an existing one (e.g. DateTool.getTimeZone(String zoneId)
would be handy).
Thanks,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Calling static methods, revisited
Posted by Christopher Schultz <ch...@christopherschultz.net>.
It looks like this is the same as
https://issues.apache.org/jira/projects/VELOCITY/issues/VELOCITY-952 and is
a much bigger issue.
See also
https://issues.apache.org/jira/projects/VELOCITY/issues/VELOCITY-968
On Wed, Sep 27, 2023 at 6:03 PM Christopher Schultz <
chris@christopherschultz.net> wrote:
> All,
>
> (This is all in the context of Velocity 1.7, but I'm not sure anything
> has changed through 2.x.)
>
> Sometimes you want to call a static method. Past workarounds are ugly
> but get the job done. For example:
>
> #set($string = "")
> $string.format($locale, "format string", args)
>
> I have a case where I've been working around java.util.TimeZone like this:
>
> #set($tz = $dateIHave.timeZone)
> #set($utc = $tx.getTimeZone('UTC'))
> ... use $utc
>
> In recent versions of Java (I'm using Java 17 at the moment), I'm
> getting this error:
>
> Exception: org.apache.velocity.exception.VelocityException:
> ASTMethod.execute() : exception invoking method 'getTimeZone' in class
> sun.util.calendar.ZoneInfo
> Stack Trace:
> org.apache.velocity.exception.VelocityException: ASTMethod.execute() :
> exception invoking method "getTimeZone" in class sun.util.calendar.ZoneInfo
>
> org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:208)
> ...
>
> I'm intending to call java.util.TimeZone.getTimeZone which should be
> fine. But the runtime type of $tz ends up being
> sun.util.calendar.ZoneInfo which, unfortunately, defines its own static
> getTimeZone method whose signature matches that of java.util.TimeZone
> but is not callable due to module.
>
> In this case, is it possible for me to make a call to
> java.util.TimeZone.getTimeZone, or is it time to write a new Tool or
> customize an existing one (e.g. DateTool.getTimeZone(String zoneId)
> would be handy).
>
> Thanks,
> -chris
>