Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-1389

Coercion to numeric types does not check for null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 5.0.3
    • 5.0.6
    • Framework
    • None
    • N/A

    Description

      When a TextField form element is bound to a numeric property (Double, Integer, aso) and no value is provided in the form (perfectly valid if the field is optional) the coercion code throws NullPointerException when trying to call new Double(null). The coercion code should check for null and not call the constructor with a null argument.

      On the other hand, if this is considered normal behaviour, there should be a way to bind a TextField to a numeric property and to make it optional on the form.

      Here follows a test case illustrating the problem:

      DoubleCoercionTest.html:
      ------------------------------------

      <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
      <body>
      <form t:type="Form">
      <p><input t:type="TextField" t:value="doubleTest" size="40"/>
      <input t:type="Submit"/></p>
      </form>
      </body>
      </html>

      DoubleCoercionTest.java:
      -----------------------------------
      import org.apache.tapestry.annotations.Persist;

      public class DoubleCoercionTest
      {
      @Persist
      private Double doubleTest;
      public Double getDoubleTest()

      {return doubleTest;}

      public void setDoubleTest(Double doubleTest)

      {this.doubleTest = doubleTest;}

      }

      Attachments

        Activity

          People

            hlship Howard Lewis Ship
            bcalmac Bogdan Calmac
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: