Skip to content

AopTestUtils.getUltimateTargetObject results in stack overflow for proxy backed by LazyInitTargetSource #29215

Closed as not planned
@lako12

Description

@lako12

Security configuration class

    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public class SecurityConf {
    
        @Bean
        public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authenticationConfiguration) throws Exception {
            return authenticationConfiguration.getAuthenticationManager();
        }
    }

Controller

    @RestController
    public class Controller {
        
        @GetMapping("/test")
        public String test(){
            return "test";
        }
    }

Test class

    @ExtendWith(SpringExtension.class)
    @WebMvcTest(controllers = Controller.class)
    @ComponentScan("com.example.demo")
    public class DemoApplicationTests {
    
        @Test
        public void test() {
        }
    }

I have a simple application, if I try to start the main it works, however when I start my test class I get this error:

java.lang.StackOverflowError
            	at java.base/java.lang.StackTraceElement.of(StackTraceElement.java:526)
            	at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:828)
            	at java.base/java.lang.Throwable.getStackTrace(Throwable.java:820)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:79)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
            	at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
        and it always continues the same way ...

In debug I tried to recover the error, but I only see this java.lang.IllegalStateException: Failed to unwrap proxied object.

The test only works if I remove the authenticationManagerBean, but i need authenticationManagerBean to inject AutthenticationManager in my app.

I know that I could use WebSecurityConfigurerAdapter and then add the bean going to override the method of this class. But as WebSecurityConfigurerAdapter is deprecated, I would not want to use it.

This problem arose from the fact that I have switched from WebSecurityConfigurerAdapter to SecurityFilterChain and am getting this error as I changed the config class.

I created this simple project which replicates the error of my main project. If you try to start the application it works, but the test doesn't. https://github.com/lako12/demo

The project is very simple, there are only 3 classes plus a test class.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions