You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Denny <de...@gmail.com> on 2007/08/25 15:36:44 UTC

T5: Coercion of null to type java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal) failed: java.lang.NullPointerException

I have met the T5's bug, https://issues.apache.org/jira/browse/TAPESTRY-1648

I have a domain class, which has a BigDecimal property. While I submit form,
it would happen the bug "TAPESTRY-1648".

Caused by: org.apache.tapestry.ioc.internal.util.TapestryException: Failure
writing parameter value of component
basicinformation/AddOrEditDriver:carlong: Coercion of null to type
java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal)
failed: java.lang.NullPointerException [at
classpath:com/javaeye/dengyin2000/gtts/pages/basicinformation/AddOrEditDriver.html,
line 50, column 115]
    at
org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.writeParameter
(InternalComponentResourcesImpl.java:239)
    at
org.apache.tapestry.corelib.base.AbstractTextField._$update_parameter_value(
AbstractTextField.java)
    at org.apache.tapestry.corelib.base.AbstractTextField.processSubmission(
AbstractTextField.java:181)
    at org.apache.tapestry.corelib.base.AbstractField.processSubmission(
AbstractField.java:200)
    at org.apache.tapestry.corelib.base.AbstractField.access$100(
AbstractField.java:45)
    at
org.apache.tapestry.corelib.base.AbstractField$ProcessSubmissionAction.execute
(AbstractField.java:114)
    at
org.apache.tapestry.corelib.base.AbstractField$ProcessSubmissionAction.execute
(AbstractField.java:108)
    at org.apache.tapestry.corelib.components.Form.onAction(Form.java:364)
    ... 45 more
Caused by: java.lang.RuntimeException: Coercion of null to type
java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal)
failed: java.lang.NullPointerException
    at org.apache.tapestry.ioc.internal.services.TypeCoercerImpl.coerce(
TypeCoercerImpl.java:154)
    at $TypeCoercer_1149d2e0ddf.coerce($TypeCoercer_1149d2e0ddf.java)
    at
org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.writeParameter
(InternalComponentResourcesImpl.java:233)
    ... 52 more
Caused by: java.lang.NullPointerException
    at java.math.BigDecimal.<init>(BigDecimal.java:594)
    at org.apache.tapestry.ioc.services.TapestryIOCModule$7.coerce(
TapestryIOCModule.java:219)
    at org.apache.tapestry.ioc.services.TapestryIOCModule$7.coerce(
TapestryIOCModule.java:217)
    at org.apache.tapestry.ioc.services.CoercionTuple$CoercionWrapper.coerce
(CoercionTuple.java:53)
    at org.apache.tapestry.ioc.internal.services.CompoundCoercion.coerce(
CompoundCoercion.java:48)
    at org.apache.tapestry.ioc.internal.services.TypeCoercerImpl.coerce(
TypeCoercerImpl.java:150)
    ... 54 more

I have contribute a BigDecimal translator, Yes, I know it's a T5 bug and it
would be fix in version 5.0.6. I searched tapestry mailling list, but I
haven't gotten the answer. Does anybody know how to fix it? do your guys
don't meet this problem. Or I should modify the T5.0.5' source code?

Thanks.

-- 
Regards

Denny
Site: http://dengyin2000.javaeye.com

Re: T5: Coercion of null to type java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal) failed: java.lang.NullPointerException

Posted by Denny <de...@gmail.com>.
I am sure my BigDecimal translator is no problem, I have fixed this problem
by modify the Tapestry ioc's source code. ok, here is my translator.


   1. package com.javaeye.dengyin2000.gtts.tapestry;
   2.
   3. import java.math.BigDecimal;
   4.
   5. import org.apache.tapestry.Translator;
   6. import org.apache.tapestry.ValidationException;
   7. import org.apache.tapestry.ioc.Messages;
   8. import org.apache.tapestry.ioc.internal.util.InternalUtils;
   9.
   10. public class BigDecimalTranslator implements
    Translator<BigDecimal> {
   11.
   12.     public
    BigDecimal parseClient(String clientValue, Messages messages)
   13.             throws ValidationException {
   14.         if (InternalUtils.isBlank(clientValue))
   15.             return null;
   16.
   17.         try
   18.         {
   19.             return new BigDecimal(clientValue.trim());
   20.         }
   21.         catch (NumberFormatException ex)
   22.         {
   23.             throw new ValidationException(messages.format(
   "number-format-exception", clientValue));
   24.         }
   25.     }
   26.
   27.     public String toClient(BigDecimal value) {
   28.         return value == null ? "" : value.toString();
   29.     }
   30.
   31. }

and in AppModule.java


   1. public static void contributeTranslatorDefaultSource(
   2.         MappedConfiguration<Class, Translator> configuration)
   3. {
   4.     configuration.add(BigDecimal.class, new
    BigDecimalTranslator());
   5. }
   6.
   7. public static void contributeTranslatorSource(
   8.         MappedConfiguration<String, Translator> configuration)
   9. {
   10.     configuration.add("bigdecimal",  new
    BigDecimalTranslator());
   11. }

It's a real bug in tapestry ioc 5.0.5.


   1.
   // String to BigDecimal is important, as String->Double->BigDecimal
would lose

   2. // precision.
   3.
   4. add(configuration, String.class, BigDecimal.class, new
    Coercion<String, BigDecimal>()
   5. {
   6.     public BigDecimal coerce(String input)
   7.     {
   8.         return new BigDecimal(input);
   9.     }
   10.

So I modify code to :


   1.
   // String to BigDecimal is important, as String->Double->BigDecimal
would lose

   2. // precision.
   3.
   4. add(configuration, String.class, BigDecimal.class, new
    Coercion<String, BigDecimal>()
   5. {
   6.     public BigDecimal coerce(String input)
   7.     {
   8.             if (input == null || input.trim().length() == 0)
   9.                 return null;
   10.             return new BigDecimal(input);
   11.     }
   12. });


And the problem has gone.




On 8/27/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
>
> Please show the code for your translator.
>
> Cheers,
> Nick.
>
>
> Denny wrote:
> > I have contribute a BigDecimal translator, Yes, I know it's a T5 bug and
> it
> > would be fix in version 5.0.6. I searched tapestry mailling list, but I
> > haven't gotten the answer. Does anybody know how to fix it? do your guys
> > don't meet this problem. Or I should modify the T5.0.5' source code?
> >
> > Thanks.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Regards

Denny
Site: http://dengyin2000.javaeye.com

Re: T5: Coercion of null to type java.math.BigDecimal (via null --> String, String --> java.math.BigDecimal) failed: java.lang.NullPointerException

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Please show the code for your translator.

Cheers,
Nick.


Denny wrote:
> I have contribute a BigDecimal translator, Yes, I know it's a T5 bug and it
> would be fix in version 5.0.6. I searched tapestry mailling list, but I
> haven't gotten the answer. Does anybody know how to fix it? do your guys
> don't meet this problem. Or I should modify the T5.0.5' source code?
> 
> Thanks.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org