Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Strange freemarker exception

Posted on 2004-11-25
25
Medium Priority
?
510 Views
Last Modified: 2012-05-05
Have no ideas, please help

SEVERE:

Methodparse on gran.tools.formatter.DateFormatter
The problematic instruction:
----------
==> ${addval.df.parse(msg.getTime())} [on line 441, column 5 in 1]
 in user-directive message [on line 807, column 1 in 1]
 in user-directive page [on line 510, column 1 in 1]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Methodparse on gran.tools.formatter.DateFormatter
      at freemarker.ext.beans.OverloadedMethodModel.exec(OverloadedMethodModel.java:112)
      at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
      at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
      at freemarker.core.Expression.getStringValue(Expression.java:93)
      at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.MixedContent.accept(MixedContent.java:92)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.Environment.visit(Environment.java:208)
0
Comment
Question by:maximkr
  • 8
  • 8
  • 7
  • +1
24 Comments
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 400 total points
ID: 12673405
Seems as msg.getTime() returns an invalid format. A format addval.df.parse() can't parse
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673427
what does getTime() return?

is it a java.util.Date object?
0
 

Author Comment

by:maximkr
ID: 12673436
   import java.sql.Timestamp;
...
    public Timestamp getTime() {
        return allowedByAcl ? message.getTime() : null;
    }

and

    public String parse(java.sql.Timestamp param) {
        if (param == null)
            return null;

        DateFormat df = this.getDateFormat();
        return new String(df.format(param));
    }

What can be wrong here ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 37

Expert Comment

by:zzynx
ID: 12673450
This
   >> return new String(df.format(param));
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673462
what is "df" and how is it created?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12673468
In other words, post the code of getDateFormat() ;°)
0
 

Author Comment

by:maximkr
ID: 12673482
   public Calendar getCalendar() {
        return new GregorianCalendar(this.timezone, this.locale);
    }

    public DateFormat getDateFormat() {
        DateFormat f = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, this.getLocale());
        f.setCalendar(this.getCalendar());
        return f;
    }
0
 

Author Comment

by:maximkr
ID: 12673487
I forgot important stacktrace:
Underlying cause:

No signature of method parse matches (java.lang.Object)
The problematic instruction:
----------
==> ${addval.df.parse(msg.getTime())} [on line 441, column 5 in 1]
 in user-directive message [on line 807, column 1 in 1]
 in user-directive page [on line 510, column 1 in 1]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: No signature of method parse matches (java.lang.Object)
      at freemarker.ext.beans.MethodMap.getMostSpecific(MethodMap.java:127)
      at freemarker.ext.beans.OverloadedMethodModel.exec(OverloadedMethodModel.java:104)
      at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
      at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
      at freemarker.core.Expression.getStringValue(Expression.java:93)
      at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.MixedContent.accept(MixedContent.java:92)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.Environment.visit(Environment.java:208)
      at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.MixedContent.accept(MixedContent.java:92)
      at freemarker.core.Environment.visit(Environment.java:171)
      at freemarker.core.Macro$Context.runMacro(Macro.java:164)
      at freemarker.core.Environment.visit(Environment.java:470)
      at freemarker.core.UnifiedCall.accept(UnifiedCall.java:128)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673493
You shouldn't need:

        f.setCalendar( this.getCalendar() );

But I can't see how that's a problem :-/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673497
Ahhhh....  right...for some reason, it's looking for a method:

    public String parse( Object timestamp )

Which is a bit odd....as msg.getTime returns a Timestamp...
0
 

Author Comment

by:maximkr
ID: 12673503
I can only add that all this works on our test database, but fail on production.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 1600 total points
ID: 12673506
I'm guessing:

        return allowedByAcl ? message.getTime() : null;

is returning null, and then it can't find a parse method that takes null (as null has no type, it's trying to send it to a method of type Object)

does:

        ${addval.df.parse((java.sql.Timestamp)msg.getTime())}

work?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673511
Can you print out the value of "allowedByAcl"?
0
 
LVL 35

Expert Comment

by:girionis
ID: 12673512
>  ${addval.df.parse(msg.getTime())} [on line 441, column 5 in 1]

Show us that bit of code.

0
 

Author Comment

by:maximkr
ID: 12673516
Only idea:
Possible, it try to determine parameter type by value ? getTime return null sometimes...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673522
> Possible, it try to determine parameter type by value ? getTime return null sometimes...

that's what I said isn't it?

;-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12673584
That's what Tim told you, yes. Try casting like he said.
0
 

Author Comment

by:maximkr
ID: 12673685
Casting don't  work (even more strange exception occurs), but the following code works fine:
<#if msg.getTime()?exists>
<td>${addval.df.parse(msg.getTime())}</td>
<#else>
<td>&nbsp;</td>
</#if>

Thank you!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12673690
That's also a solution of course. OK!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12673829
Somewhat surprised I didn't get some points for my comments :/
0
 

Author Comment

by:maximkr
ID: 12673845
Possible I missed something in rules (give me a link, I am novice here), but I've think that points for solution, not for attention, correct ?

Anyway, thank you very much too.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12673848
Good luck with it maximkr :-)

Tim
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12673858
>> I've think that points for solution, not for attention,
That's right. But I'm not talking about mere attention.
My first comment:
>> Seems as msg.getTime() returns an invalid format. A format addval.df.parse() can't parse
was a good pointer in the right direction I thought.
And points are also given for "assisted answers" (See the EE help pages)

>> Anyway, thank you very much too.
All right, that's OK.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12674455
Thanks maximkr :°)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question