How to debug this code?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to debug this code?

Erik  Pragt
Hi all,

I'm upgrading from 1.3.7 to 2.0.3, and my tests stopped working (at the moment, out 3500 tests, only 800 are still working). For some it's quite clear, but some code is miraculously failing. A small example of code which used to work in Grails 1.3.7, but now fails:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                payment: new Payment(
                        accountNumber: "1234567",
                        payer: new Person(
                                surname: "Payer"
                        )),
                person: new Person(
                        surname: "Person"
                )
        )

        assert customer.payment.accountNumber == '1234567'
    }
}

Which fails with the following error:

java.lang.NullPointerException: Cannot get property 'accountNumber' on null object

If I change my code to the following:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                person: new Person(
                        surname: "Person"
                )
        )

        customer.payment = new Payment(
                accountNumber: "1234567",
                payer: new Person(
                        surname: "Payer"
        ))

        assert customer.payment.accountNumber == '1234567'
    }
}

This code works. I don't have any constructors, setters, or anything like that specified. The only thing which drew my attention is that Customer and Person are domain classes, while Payment isn't. I tried to reproduce this in a sample app, but there it works without any problems, even when I split it into domain classes and src/groovy classes.

Any suggestions why this might be, or how I can debug this?

Thanks,

Erik
Reply | Threaded
Open this post in threaded view
|

Re: How to debug this code?

Lari Hotari -
Hi,

Looks similar to http://jira.grails.org/browse/GRAILS-8972 .

Try to add this constraint to Customer:

  static constraints = {
     payment bindable:true
  }

I believe you can debug it by settting a breakpoint in org.codehaus.groovy.grails.plugins.web.api.ControllersDomainBindingApi.initialize(Object,Map) method.

Regards,


Lari


12.04.2012 19:42, Erik Pragt wrote:
Hi all,

I'm upgrading from 1.3.7 to 2.0.3, and my tests stopped working (at the moment, out 3500 tests, only 800 are still working). For some it's quite clear, but some code is miraculously failing. A small example of code which used to work in Grails 1.3.7, but now fails:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                payment: new Payment(
                        accountNumber: "1234567",
                        payer: new Person(
                                surname: "Payer"
                        )),
                person: new Person(
                        surname: "Person"
                )
        )

        assert customer.payment.accountNumber == '1234567'
    }
}

Which fails with the following error:

java.lang.NullPointerException: Cannot get property 'accountNumber' on null object

If I change my code to the following:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                person: new Person(
                        surname: "Person"
                )
        )

        customer.payment = new Payment(
                accountNumber: "1234567",
                payer: new Person(
                        surname: "Payer"
        ))

        assert customer.payment.accountNumber == '1234567'
    }
}

This code works. I don't have any constructors, setters, or anything like that specified. The only thing which drew my attention is that Customer and Person are domain classes, while Payment isn't. I tried to reproduce this in a sample app, but there it works without any problems, even when I split it into domain classes and src/groovy classes.

Any suggestions why this might be, or how I can debug this?

Thanks,

Erik


Reply | Threaded
Open this post in threaded view
|

Re: How to debug this code?

Erik  Pragt
Hi Lari,

Thanks for the help! I'll certainly try this out. The weird thing however is that I'm using 2.0.3, so it seems like this bug hasn't been fixed.

I'll debug it on monday.

Thanks!

Erik

On Apr 13, 2012, at 10:35 AM, Lari Hotari wrote:

Hi,

Looks similar to http://jira.grails.org/browse/GRAILS-8972 .

Try to add this constraint to Customer:

  static constraints = {
     payment bindable:true
  }

I believe you can debug it by settting a breakpoint in org.codehaus.groovy.grails.plugins.web.api.ControllersDomainBindingApi.initialize(Object,Map) method.

Regards,


Lari


12.04.2012 19:42, Erik Pragt wrote:
Hi all,

I'm upgrading from 1.3.7 to 2.0.3, and my tests stopped working (at the moment, out 3500 tests, only 800 are still working). For some it's quite clear, but some code is miraculously failing. A small example of code which used to work in Grails 1.3.7, but now fails:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                payment: new Payment(
                        accountNumber: "1234567",
                        payer: new Person(
                                surname: "Payer"
                        )),
                person: new Person(
                        surname: "Person"
                )
        )

        assert customer.payment.accountNumber == '1234567'
    }
}

Which fails with the following error:

java.lang.NullPointerException: Cannot get property 'accountNumber' on null object

If I change my code to the following:

class MyCommandTests {
    @Test
    void testSomething() {
        Customer customer = new Customer(
                person: new Person(
                        surname: "Person"
                )
        )

        customer.payment = new Payment(
                accountNumber: "1234567",
                payer: new Person(
                        surname: "Payer"
        ))

        assert customer.payment.accountNumber == '1234567'
    }
}

This code works. I don't have any constructors, setters, or anything like that specified. The only thing which drew my attention is that Customer and Person are domain classes, while Payment isn't. I tried to reproduce this in a sample app, but there it works without any problems, even when I split it into domain classes and src/groovy classes.

Any suggestions why this might be, or how I can debug this?

Thanks,

Erik