Skip to content

ClassPropertyFetcher does not recognize properties that have their second letter capitalized #10403

@JanKanis

Description

@JanKanis

Steps to Reproduce

  1. Create a domain class like this:
class TestDomainClass {
  String cType

  static constraints = {
    cType nullable: true
  }
}

  1. Try to save an instance of the class

Expected Behaviour

The class should load and be usable

Actual Behaviour

The validation code for the class throws an exception:

java.lang.IllegalArgumentException: object is not an instance of declaring class
	at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:62)
	at org.grails.validation.ConstrainedPropertyBuilder.doInvokeMethod(ConstrainedPropertyBuilder.java:74)
	at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:67)
	at mypackage.TestDomainClass._clinit__closure1(TestDomainClass.groovy:7)
	at mypackage.TestDomainClass._clinit__closure1(TestDomainClass.groovy)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:408)
	at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraintsMap(DefaultConstraintEvaluator.java:239)
	at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:132)
	at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:119)
	at org.grails.validation.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:108)
	at org.grails.core.DefaultGrailsDomainClass.initializeConstraints(DefaultGrailsDomainClass.java:755)
	at org.grails.core.DefaultGrailsDomainClass.getConstrainedProperties(DefaultGrailsDomainClass.java:746)
	at org.grails.validation.GrailsDomainClassValidator.validate(GrailsDomainClassValidator.java:76)
	at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:122)
	at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
	at mypackage.TestDomainClassSpec.$tt__$spock_feature_1_0(TestDomainClassSpec.groovy:15)

Environment Information

  • Operating System: Linux Ubuntu 16.10
  • Grails Version: 3.2.3
  • JDK Version: 1.8.0_91
  • Container Version (If Applicable): n/a

Problem analysis

in org.grails.core.util.ClassPropertyFetcher line 133 the code tries to figure out if a method is a property getter, and if so calculate the property name. The code only checks if the method name starts with "get" followed by a capital letter. This misses properties like xAge that start with a small letter followed by a capital, as such properties have getters of the form getxAge().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions