robertjstroud
06/17/2024, 4:52 PMUserRole
class created by the spring-security-core
plugin, specifically:
static UserRole get(long userId, long roleId) {
criteriaFor(userId, roleId).get()
^
[Static type checking] - cannot return value of type java.lang.Object on method returning type application.UserRole
}
Has anyone seen this before or got any suggestions for how to resolve the issue? It only occurs when I set grailsVersion=6.2.0
in gradle.properties
.
Thanks,
Robertpuneetbehl
06/17/2024, 5:13 PMcriteriaFor
or try adding @CompileDynamic
to the method.
We have updated to Apache Groovy 3.0.21 which might have been the root cause here but it is difficult say anything from this information only.robertjstroud
06/17/2024, 5:18 PMUserRole
class appears to be identical to the version described in the spring-security-core
plugin manual:
https://grails.github.io/grails-spring-security-core/6.0.x/index.html#personAuthorityClass
In particular, the criteriaFor
method looks like this:
private static DetachedCriteria criteriaFor(long userId, long roleId) {
UserRole.where {
user == User.load(userId) &&
role == Role.load(roleId)
}
}
robertjstroud
06/17/2024, 5:22 PMgroovyVersion=3.0.21
in my gradle.properties
, but that didn't seem to help.robertjstroud
06/17/2024, 5:31 PM@CompileDynamic
to the method cures the problem, but this isn't a very satisfactory solution because the code compiled without any problems under Grails 6.1.1 and was autogenerated by the spring-security-core
plugin a long time ago...tylervz
06/17/2024, 5:55 PMcriteriaFor
to a UserRole
.
static UserRole get(long userId, long roleId) {
criteriaFor(userId, roleId).get() as UserRole
}
@puneetbehl would you recommend I report this as a bug with Groovy (and include an example repository that demonstrates the issue) or open up a pull request with grails-spring-security-core
plugin so that the autogenerated UserRole
class has my workaround?robertjstroud
06/17/2024, 5:59 PMrobertjstroud
06/17/2024, 6:08 PMcriteriaFor
method is a DetachedCriteria
that selects a UserRole
, so in principle, criteriaFor(...).get()
should be a UserRole
object.robertjstroud
06/17/2024, 6:11 PMcriteriaFor(...).get()
expression to a UserRole
object implicitly, otherwise, the code would have generated a static type error.robertjstroud
06/17/2024, 6:12 PMtylervz
06/17/2024, 7:58 PMUserRole.groovy
file from my other project where I had the issue you were encountering too and then I noticed one key difference. In my sample application, the criteriaFor
method has a different signature.
private static DetachedCriteria<UserRole> criteriaFor(long userId, long roleId) {
UserRole.where {
user == User.load(userId) &&
role == Role.load(roleId)
}
}
To reproduce the static compilation error in my sample app, I had to to change the signature to private static DetachedCriteria criteriaFor(long userId, long roleId)
. I don't know what version of Spring Security Core changed that signature, but I don't think the static compilation error is a Groovy bug.robertjstroud
06/17/2024, 8:15 PM