Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

StackOverflowError when using Spring 4.3 #184

Open
henrik242 opened this issue Jul 6, 2016 · 15 comments · May be fixed by #192
Open

StackOverflowError when using Spring 4.3 #184

henrik242 opened this issue Jul 6, 2016 · 15 comments · May be fixed by #192

Comments

@henrik242
Copy link

henrik242 commented Jul 6, 2016

I am trying to upgrade to Spring 4.3.0, but I am unable to initialize the spring context:

[ERROR] 09:25:31  Context initialization failed []
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthCheckBeanPostProcessor' defined in class path resource [com/ryantenney/metrics/spring/config/annotation/DelegatingMetricsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.beans.factory.config.BeanPostProcessor]: Factory method 'healthCheckBeanPostProcessor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getHealthCheckRegistry' defined in class path resource [com/ryantenney/metrics/spring/config/annotation/DelegatingMetricsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.codahale.metrics.health.HealthCheckRegistry]: Factory method 'getHealthCheckRegistry' threw exception; nested exception is java.lang.IllegalStateException: Failed to introspect annotations on public com.codahale.metrics.health.HealthCheckRegistry com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getHealthCheckRegistry()
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.0.RELEASE.jar:4.3.0.RELEASE]
[... more stuff ...]
Caused by: java.lang.StackOverflowError
    at java.lang.reflect.Method.hashCode(Method.java:330) ~[?:1.8.0_65]
    at java.util.HashMap.hash(HashMap.java:338) ~[?:1.8.0_65]
    at java.util.HashMap.put(HashMap.java:611) ~[?:1.8.0_65]
    at java.util.HashSet.add(HashSet.java:219) ~[?:1.8.0_65]
    at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1119) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1183) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1208) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1086) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1060) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotationAttributes(AnnotatedElementUtils.java:656) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(AnnotatedElementUtils.java:730) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:314) ~[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.getHealthCheckRegistry(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerComposite.getHealthCheckRegistry(MetricsConfigurerComposite.java:68) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getHealthCheckRegistry(DelegatingMetricsConfiguration.java:69) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.CGLIB$getHealthCheckRegistry$3(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e$$FastClassBySpringCGLIB$$7853f663.invoke(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.getHealthCheckRegistry(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerComposite.getHealthCheckRegistry(MetricsConfigurerComposite.java:68) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getHealthCheckRegistry(DelegatingMetricsConfiguration.java:69) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.CGLIB$getHealthCheckRegistry$3(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e$$FastClassBySpringCGLIB$$7853f663.invoke(<generated>) ~[metrics-spring-3.1.3.jar:?]
    [... repeat 100 times ...]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.getHealthCheckRegistry(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerComposite.getHealthCheckRegistry(MetricsConfigurerComposite.java:68) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getHealthCheckRegistry(DelegatingMetricsConfiguration.java:69) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.CGLIB$getHealthCheckRegistry$3(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e$$FastClassBySpringCGLIB$$7853f663.invoke(<generated>) ~[metrics-spring-3.1.3.jar:?]
@henrik242
Copy link
Author

henrik242 commented Jul 6, 2016

Seems to happen when a @Configuration class is annotated with @EnableMetrics. I get the same result in Spring 4.3.1.

@ryantenney
Copy link
Owner

Which stack frame or set of stack frames repeats 100 times?

@henrik242
Copy link
Author

henrik242 commented Jul 6, 2016

Not exactly a hundred, but several dozens:

    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.0.RELEASE.jar:4.3.0.RELEASE]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.getHealthCheckRegistry(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerComposite.getHealthCheckRegistry(MetricsConfigurerComposite.java:68) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getHealthCheckRegistry(DelegatingMetricsConfiguration.java:69) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e.CGLIB$getHealthCheckRegistry$3(<generated>) ~[metrics-spring-3.1.3.jar:?]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2cc24d5e$$FastClassBySpringCGLIB$$7853f663.invoke(<generated>) ~[metrics-spring-3.1.3.jar:?]

@henrik242
Copy link
Author

@ryantenney Are you able to reproduce it, and/or do you need more info from me?

@henrik242
Copy link
Author

I'm trying to understand what @EnableMetrics does. Is it only used to enable scanning of the @Metric annotation?

@rafal-glowinski
Copy link

    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2c4ac852.getMetricRegistry(<generated>) ~[metrics-spring-3.1.3.jar:na]
    at com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerComposite.getMetricRegistry(MetricsConfigurerComposite.java:52) ~[metrics-spring-3.1.3.jar:na]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration.getMetricRegistry(DelegatingMetricsConfiguration.java:59) ~[metrics-spring-3.1.3.jar:na]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2c4ac852.CGLIB$getMetricRegistry$2(<generated>) ~[metrics-spring-3.1.3.jar:na]
    at com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration$$EnhancerBySpringCGLIB$$2c4ac852$$FastClassBySpringCGLIB$$2acb39f3.invoke(<generated>) ~[metrics-spring-3.1.3.jar:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.1.RELEASE.jar:4.3.1.RELEASE]

It happens during the call to: "com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration#getMetricRegistry" because "delegates" contain an instance of "DelegatingMetricsConfiguration" which causes Stack Overflow.

@roykachouh
Copy link

Yes, this is happening for me as well. I upgrade to boot 1.4.x and the MetricRegistry bean can no longer create. It looks like recursion in the DelegatingMetricsConfiguration#getMetricRegistry.

Metric registry is null, and the delegates recurse.

screenshot 2016-07-16 12 09 06

@ryantenney
Copy link
Owner

@roykachouh @henrik242 @rafal-glowinski do any of you have AspectJ Autoproxying enabled?

@henrik242
Copy link
Author

@ryantenney Nope, not that I'm aware of.

@roykachouh
Copy link

roykachouh commented Jul 26, 2016

@ryantenney thanks for looking into this...no i don't have aspectj autoproxying enabled...i even tried disabling the auto-configuration just in case...but to no avail, the stack still overflows...

spring:
  aop:
    auto: false

@chornyi
Copy link

chornyi commented Aug 3, 2016

For now I "fixed" this by removing @EnableMetrics and adding this:

@Configuration
public class CustomDelegatingMetricsConfiguration extends DelegatingMetricsConfiguration {

    @Override
    @Autowired(required = false)
    public void setMetricsConfigurers(final List<MetricsConfigurer> configurers) {
    }
}

@roykachouh
Copy link

Yep, temporarily got around it by removing EnableMetrics

On Wed, Aug 3, 2016 at 5:46 PM Dmitry Chornyi [email protected]
wrote:

For now I "fixed" this by removing @EnableMetrics and adding this:

@configuration
public class CustomDelegatingMetricsConfiguration extends DelegatingMetricsConfiguration {

@Override
@Autowired(required = false)
public void setMetricsConfigurers(final List<MetricsConfigurer> configurers) {
}

}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#184 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB_QXtAcdNMOW1K82bsmqZ2kUxtsIaLyks5qcQw7gaJpZM4JF1GW
.

@hello-josh
Copy link

hello-josh commented Sep 12, 2016

I'm having the same issue and it looks like it is because the @EnableMetrics annotation does not work correctly on a @Configuration POJO.

This works:

@Configuration
@EnableMetrics
public class MetricsConfig extends MetricsConfigurerAdapter {
}

This does not and causes the stack overflow

@Configuration
@EnableMetrics
public class MetricsConfig {
}

This repo illustrates it: https://github.com/Trii/SpringBootMetricsSpringBug
Clone and run gradle bootRun to see the stackoverflow. Open src/main/java/trii/SampleConfig.java and uncomment the import and extends to see it working.

Maybe this is intended behavior and more of a usage error.

@sfussenegger
Copy link

sfussenegger commented Nov 29, 2016

I ran into the same problem. I've tracked the issue down to DelegatingMetricsConfiguration.setMetricsConfigurers(List<MetricsConfigurer> configurers). The issue is that configurers contains itself (i.e. this), obviously a big no-no for a list of delegates. There must have been a change in Spring 1.4 that allows autowiring objects with themselves.

The simplest solution therefore seems to be not to implement MetricsConfigurer in DelegatingMetricsConfiguration

@laur89
Copy link

laur89 commented Jun 27, 2017

This issue should be closed, as it doesn't reproduce with spring 4.3.7 (spring boot 1.5.X).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants