[
https://issues.apache.org/jira/browse/GROOVY-11204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17779196#comment-17779196
]
Eric Milles commented on GROOVY-11204:
--------------------------------------
Here is what is going on. There are two methods available:
{code:java}
SecurityConfigurer AbstractConfiguredSecurityBuilder.apply(
org.springframework.security.config.annotation.SecurityConfigurer)
SecurityConfigurerAdapter AbstractConfiguredSecurityBuilder.apply(
org.springframework.security.config.annotation.SecurityConfigurerAdapter)
{code}
[{{SecurityConfigurer}}|https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/SecurityConfigurer.html]
is an interface and
[{{SecurityConfigurerAdapter}}|https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/SecurityConfigurerAdapter.html]
is an abstract class.
The method selection logic in
{{MetaClassImpl}}/[{{MetaClassHelper}}|https://github.com/apache/groovy/blob/77f525dd256f4ba033fc1ebe997922812cb8b7fa/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java#L311]
find a distance of 3 between {{MyConfigurer}} and {{SecurityConfigurer}} and a
distance of (27 << 23) between {{MyConfigurer}} and
{{SecurityConfigurerAdapter}}. Therefore the interface-parameter method is
selected.
The preference for interfaces was established by GROOVY-3019 or earlier.
> Incorrect overload selection for subclasses
> -------------------------------------------
>
> Key: GROOVY-11204
> URL: https://issues.apache.org/jira/browse/GROOVY-11204
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 4.0.12
> Reporter: Christopher Smith
> Assignee: Eric Milles
> Priority: Major
>
> I'm writing a Spring Security configurer and trying to add it to my
> configuration using {{apply(C)}}, but the Groovy compiler selects the wrong
> overload, and necessary initialization is not performed.
> {code:groovy}
> @Grab('org.springframework.security:spring-security-config:5.7.11')
> import
> org.springframework.security.config.annotation.authentication.builders.*
> import org.springframework.security.config.annotation.web.configurers.*
> import org.springframework.security.config.annotation.web.builders.*
> @Grab('org.springframework.security:spring-security-web:5.7.11')
> import org.springframework.security.web.*
> @Grab('javax.servlet:servlet-api:2.5')
> // AbstractHttpConfigurer extends SecurityConfigurerAdapter
> class MyConfigurer extends AbstractHttpConfigurer<MyConfigurer, HttpSecurity>
> {}
> // configuration
> @Bean
> SecurityFilterChain securityFilterChain(HttpSecurity http) {
> http.apply(new MyConfigurer())
> // ^ should select apply(SecurityConfigurerAdapter), but selects
> apply(SecurityConfigurer)
> .and()
> .build()
> }
> {code}
> This is probably a result of an edge case in the generics, since the bounds
> on the overloads are determined by type parameters.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)