commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy Chapman (JIRA)" <>
Subject [jira] [Commented] (OGNL-169) When setting parameters OGNL only tries to match arguments with the first accessor method
Date Thu, 13 Sep 2012 10:22:07 GMT


Andy Chapman commented on OGNL-169:

On further investigation, there is nothing wrong with findParameterTypes. 

The problem is with ognl.OgnlRuntime.getSetMethod(OgnlContext context, Class targetClass,
String propertyName) which returns the first set method for the parameter name regardless
of accessibility or the type of the property being set.

If there is more than one cached property method for the target class then the one selected
by getSetMethod is undefined (but constant due to the caching). 

The problem can be seen under struts2 with:

class Test extends ActionSupport {
   public void setWibble(String wibble);
   protected void setWibble(long wibble);

If I'm trying to do wibble=foobar then OGNL will often (not always) do getSetMethod and get
"protected void setWibble(long wibble)". This is then checked for accessibility in ognl.OgnlRuntime.setMethodValue(OgnlContext,
Object, String, Object, boolean) and fails. So, OGNL throws a no such method exception for
public void setWibble(String).

It should be fixable by changing getSetMethod to getSetMethods and returning a collection
of the possible set methods. The calling routine in each case (I think there are only 2) should
then check filter these for accessible methods and finally work through those for one with
the right parameter types.

> When setting parameters OGNL only tries to match arguments with the first accessor method
> -----------------------------------------------------------------------------------------
>                 Key: OGNL-169
>                 URL:
>             Project: Commons OGNL
>          Issue Type: Bug
>          Components: PropertyAccessors
>    Affects Versions: 3.0
>         Environment: Struts2.2.1
> Java 1.5_08
> Windows/Unix
>            Reporter: Andy Chapman
>            Assignee: Jesse Kuhnert
> I have an object with two methods:
> class Something
> {
>     public void setStartDate(Calendar date) { <some code> }
>     public void setStartDate(String date) {  <some other code> }
> }
> OGNL sometimes fails to call the second method when given a String parameter.
> I've stepped through the code in debug and what appears to be happening is that when
I try to set Something.StartDate with a string (submitting a form via struts) OGNL tries only
one method for compatibility. I can see it finding both accessor methods (it gets both) but
then it goes through looking for compatible parameters and doesn't try both.
> This has an unfortunate side effect (I think because of slight variations in java compiler).
If I build and test the application with irrelevant changes and it works some of the time.
My best guess is that every so often Java creates the .class file with one method first and
other time with the other first. 
> The work around is to rename my methods and change the jsp files so I have:
> class Something
> {
>     public void setStartDate(Calendar date) { <some code> }
>     public void setStartDateWithString(String date) {  <some other code> }
> }
> Major because it sometimes causes a system that passes all testing to then fail when
rolled out to live.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message