You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2020/08/01 23:38:00 UTC
[jira] [Resolved] (GROOVY-9653) SC: ClassCastException on delegate
object property set
[ https://issues.apache.org/jira/browse/GROOVY-9653?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun resolved GROOVY-9653.
--------------------------------
Fix Version/s: 3.0.6
4.0.0-alpha-1
Resolution: Fixed
> SC: ClassCastException on delegate object property set
> ------------------------------------------------------
>
> Key: GROOVY-9653
> URL: https://issues.apache.org/jira/browse/GROOVY-9653
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 3.0.5, 2.5.13
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.6
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> This started to fail in Groovy 2.5.13:
> {code:groovy}
> import com.fasterxml.jackson.annotation.JsonInclude
> @Grab('com.fasterxml.jackson.core:jackson-databind:2.9.9')
> import com.fasterxml.jackson.databind.ObjectMapper
> @Grab('org.springframework:spring-web:4.3.14.RELEASE')
> import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean
> @groovy.transform.CompileStatic
> final class MyObjectMapper extends ObjectMapper
> {
> MyObjectMapper()
> {
> super(mimicSpring())
> }
> private static ObjectMapper mimicSpring()
> {
> new Jackson2ObjectMapperFactoryBean().with {
> serializationInclusion = JsonInclude.Include.NON_NULL // ClassCastException: org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean cannot be cast to com.fasterxml.jackson.databind.ObjectMapper
> defaultViewInclusion = true // include w/o view tag
> failOnUnknownProperties = false
> autoDetectGettersSetters = true
> autoDetectFields = false
> afterPropertiesSet()
> return object
> }
> }
> private static final long serialVersionUID = 2643043846851474223L
> }
> println new MyObjectMapper()
> {code}
> Works fine with default (dynamic) compilation.
> In this case, the delegate (Jackson2ObjectMapperFactoryBean) and owner (MyObjectMapper) both supply a setter "setSerializationInclusion" and do not have a field of the same name. StaticCompilationVisitor/StaticTypeCheckingVisitor existsProperty fail to record the receiver type when visiting the setter.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)