Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1381 new MOP implementation task
  3. GROOVY-1387

use central coercion mechnism when setting fields/proeprties

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.0-RC-1
    • None
    • None

    Description

      If you take a look at MetaBeanProeprty:91

      if (getType() == String.class && !(newValue instanceof String))

      { newValue = newValue.toString(); }

      we are setting a property and to coercion, just because we think it might be needed here. But what if newValue is null? toString will fail then causing the proeprty not being set.

      An example for this:

      class TestPropertyAccess extends GroovyTestCase {
      void testSomething()

      { def customer = new CustomerBean(); customer.name = "a" assert customer.name == "a" customer.name = "b" assert customer.name == "b" // This assignment is ignored, why? println "set null" customer.name = null println customer.name // This should fail imho... assert customer.name == "b" // This works fine customer.setName(null) assert customer.name == null customer.setName("a") assert customer.name == "a" }

      }

      public class CustomerBean {

      private String name;

      public String getName()

      { return name; }

      public void setName(String name)

      { this.name = name; }

      }

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            blackdrag Jochen Theodorou
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: