-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Domain class getter for boolean not working #1646
Comments
If you decompile Does it? |
Thanks @jeffbrown for the quick feedback. Yes, your workaround works but the main concern for me is that another version of Groovy different than 3.0.7 is somehow being used preventing the isActive() method to be used. I decompiled the class Book.groovy and I can't see the method isActive(). I have tried this code locally using groovy 3.0.7 and it works fine:
but if I run the same code using groovy 2.5.14, the same code fails with this exception
but if I uncomment the method isActive(), the code works fine. That is why I am concerned about the right version of Groovy not being picked up somehow. |
I see. I didn't realize that was the concern. Which version is it that you believe is being picked up? |
Not sure about it, but according to the dependencies graph for the example project I guess it could be either groovy:2.5.6 (from org.grails.plugins:async:4.0.0) or groovy:2.4.19 (from com.bertramlabs.plugins:asset-pipeline-core:3.3.4). |
Here comes the fun. If we change the field active from
This script, when running in Groovy 3 works fine, but when running it in Groovy 2 I get this exception:
This makes me think even more than for any reason, the Groovy being picked up to compile the grails project is Groovy 2. Adding some references here in case they help: |
Something else we have noticed is that when the class is outside the domain class, the is getter gets properly recognised no matter whether |
That is good info. I cannot think of any way that we could be picking up a separate version of Groovy for domain classes than the rest of the system but this is good info and will be helpful. I expect the issue has more to do with domain class transformations than it relates to somehow using the wrong version of groovy for some parts of the compilation. Thank you for all of the feedback! |
Hi, I think the problem is with grails-data-mapping dirty check transformer. When there is no getter / setter, it will create one, so it can keep track of dirty properties. I've been reviewing the org.grails.compiler.gorm.DirtyCheckingTransformer class from that repo. On L209 we have boolean booleanProperty = ClassHelper.boolean_TYPE.getName().equals(returnType.getName()) By that, booleanProperty only is true when the return type is the primitive type boolean, not Boolean class. I think this is why it works with boolean and not with Boolean. I tried to change this booleanProperty so that it will be true for boolean and Boolean: boolean booleanProperty = ClassHelper.boolean_TYPE.getName().equals(returnType.getName()) || ClassHelper.Boolean_TYPE.getName().equals(returnType.getName()) I've tested that this change works with a modified GormDirtyCheckingSpec : package org.grails.datastore.gorm
import grails.gorm.annotation.Entity
import grails.gorm.tests.GormDatastoreSpec
class GormDirtyCheckingSpec extends GormDatastoreSpec {
@Override
List getDomainClasses() {
[Student]
}
void "test a new instance is dirty by default"() {
when:
Student student = new Student(name: "JD", test: false)
then:
!student.isTest()
student.isDirty()
}
}
@Entity
class Student {
String name
Boolean test
} |
@fjloma That makes more sense to me than the compiler picking up the wrong version of Groovy for domain classes. Well done! |
I've made a PR for that #1637 |
Expected Behavior
Is Groovy 3, there is a new way of accessing a boolean field with a getter like this
Actual Behaviour
The expected behaviour is not actually happening in a brand new project created using Grails 5.1.5 https://github.com/frangarcia/testprojectgrails515. This project just has a domain class domains.Book
and I have added this in Bootstrap.groovy
When running
./gradlew bootRun
, we get this exceptionand, if we add the method isActive() to the Book domain class, we get this error
Steps To Reproduce
Just run
./gradlew bootRun
and you will see one issue. Uncomment the method isActive() in the domain class Book and you will see the other issue.Environment Information
Example Application
https://github.com/frangarcia/testprojectgrails515
Version
5.1.5
The text was updated successfully, but these errors were encountered: