Search code examples
error-handlingstruts2ognl

Struts 2 setter unknown field parameters


My struts 2 (2.3.1) application at debug mode for url http://localhost/app/check.action?13239 raises such kind of exceptions

2011-12-15 14:45:06,455 DEBUG [CommonsLogger.java:68] : Setting static parameters {}
2011-12-15 14:45:06,456 DEBUG [CommonsLogger.java:68] : Setting params NONE
2011-12-15 14:45:06,456 DEBUG [CommonsLogger.java:68] : Setting params 13239 => [  ]
2011-12-15 14:45:06,461 WARN  [CommonsLogger.java:60] : Error setting expression '13239' with value '[Ljava.lang.String;@33b4450e'
ognl.InappropriateExpressionException: Inappropriate OGNL expression: 13239
        at ognl.SimpleNode.setValueBody(SimpleNode.java:312)
        at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
        at ognl.SimpleNode.setValue(SimpleNode.java:301)

I was expecting silently ignoring them according to documentation. What is the correct way to fix this problem?

By the way it seems that struts looking for a setter field for the value 13239 however I guess that it is not suitable for a property which is started by a number.


Solution

  • That is more or less a issue of your personal taste.Sometime we wants to know any time a parameter is submitted that doesn't have a matching getter/setter on the action and its a common use case in development our application and we forget a getter/setter on an action, we want to know about any possible error case.

    One possible way to is setting the logging level differently from dev to production.There was a long discussion about this on Struts2 mailing list here is the link for same

    OgnlValueStack Error setting expression warnings after upgrade from struts 2 to struts 2.1.7