4

I have this class

class ScanRequest4Command implements Validateable {

    String _ScanType

    static constraints = {
        pScanType inList:["a", "b"]
    }
}

this code worked fine in grails 2.4.4 lately, we started upgrading to grails 3.1.16

now when I try to run the code if fails and throw the following exception:

java.lang.IllegalArgumentException: object is not an instance of declaring class
    at com.evercompliant.commands.v4.ScanRequest4Command$__clinit__closure9.doCall(ScanRequest4Command.groovy:151)
    at com.evercompliant.commands.v4.ScanRequest4Command$__clinit__closure9.doCall(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command$__clinit__closure9.call(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command$__clinit__closure9.call(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command.validate(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command.validate(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.Base4Command.validateWithErrors(Base4Command.groovy:98)
    at com.evercompliant.commands.v4.PortfolioManagementBase4Command.validateWithErrors(PortfolioManagementBase4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command.super$2$validateWithErrors(ScanRequest4Command.groovy)
    at com.evercompliant.commands.v4.ScanRequest4Command.validateWithErrors(ScanRequest4Command.groovy:164)
    at com.evercompliant.commands.v4.ScanRequest4Command$validateWithErrors.call(Unknown Source)
    at com.evercompliant.data.Merchant.withTransaction(Merchant.groovy)
    at com.evercompliant.data.Merchant$withTransaction.call(Unknown Source)
    at com.evercompliant.utils.CorsFilter.doFilterInternal(CorsFilter.java:35)

which did not help much. if I remove the inList constraint the code passes, meaning the problem is in the inList constraint.

so after test-and-failed, I found out the if I change the member's name to pScanType the code passes.

so my question is this:

is the underscore not allowed in member name prefix? if so is it documented anywhere? if not then what is the problem with the code?

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
  • 1
    you have different names for your field and constraint: `_ScanType` and `pScanType` – injecteer Jan 08 '18 at 14:10
  • @injecteer yes, that's what I meant. if I change the name of the field, the code works – No Idea For Name Jan 08 '18 at 15:41
  • Maybe try with anohter grails version (https://github.com/grails/grails-core/issues/10428) – Kloker Feb 01 '18 at 07:50
  • @Kloker did reproduce in 3.3, decided later that we want grails 3.1 for now since we don't want to upgrade hibernate – No Idea For Name Feb 01 '18 at 10:00
  • @NoIdeaForName - I imagine this was all sorted ages ago, but why not just use the same name in both the filed declaration and the constraint block? Using two different names is confusing, and if it did work in the past, it probably shouldn't have. – beechovsky Jul 24 '23 at 18:00

0 Answers0