Skip to content

ConcurrentModificationException in DefaultListableBeanFactory.doGetBeanNamesForType() [SPR-13123] #17714

Closed

Description

@spring-projects-issues

Hendy Irawan opened SPR-13123 and commented

It's hard to reproduce this even for me. It only happens once and then the app works normally. Using Spring Boot 1.2.3 webapp. While Spring Boot is still initializing, and trying to open a webpage (an MVC controller request method), this could happen.

So it seems appCtx.getBean(Class) is not fully thread-safe:

final WebApplicationContext appCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(
		((ServletRequest) request.getContainerRequest()).getServletContext());
final GoogleSysConfig sysConfig = appCtx.getBean(GoogleSysConfig.class);

Stack trace:

Unexpected RuntimeException
Last cause: null

Stacktrace
Root cause:

java.util.ConcurrentModificationException
     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
     at java.util.ArrayList$Itr.next(ArrayList.java:851)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:423)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:398)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:337)
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
     at org.soluvas.web.site.google.GoogleVerifyRequestMapper.mapRequest(GoogleVerifyRequestMapper.java:76)
     at org.apache.wicket.request.mapper.CompoundRequestMapper.mapRequest(CompoundRequestMapper.java:152)
     at org.apache.wicket.request.cycle.RequestCycle.resolveRequestHandler(RequestCycle.java:190)
     at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:215)
     at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
     at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
     at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
     at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
     at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102)
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
     at org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter.doFilterInternal(MetricFilterAutoConfiguration.java:90)
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
     at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
     at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
     at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
     at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
     at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
     at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
     at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
     at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
     at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
     at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
     at io.undertow.servlet.handlers.ServletInitialHandler.jrHandle(ServletInitialHandler.java)
     at org.zeroturnaround.javarebel.integration.servlet.undertow.cbp.ServletInitialHandlerCBP.handleRequest(ServletInitialHandlerCBP.java:104)
     at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
     at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
     at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
     at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
     at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
     at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:765)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
     at java.lang.Thread.run(Thread.java:745)

display page view

Related to #4990.


Affects: 4.1.6

Issue Links:

Referenced from: commits spring-projects/spring-boot@0069e41

1 votes, 3 watchers

Activity

  1. spring-projects-issues commented on Jun 18, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This looks like a request is hitting the application context too early: Such access shouldn't even be possible before the application context finished its refresh phase, since the results of such a getBean call can be unstable in several respects if they aren't seeing the full list of bean names yet.

    We've raised spring-projects/spring-boot#3239 for tracking this with Undertow in Boot, as indicated by your stacktrace. If there is any further insight from your side, please let us know...

    Juergen

  2. spring-projects-issues commented on Jun 18, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Hendy Irawan commented

    The error happens when I access the app the first time over a browser. So indeed I'd expect the web server to wait the app initialization to finish before passing the request.

    Note that Apache Wicket (6.19.0) is implemented as a Filter (using FilterRegistrationBean), not a Servlet, which may or may not contribute to the problem. What's clear is that the first time app is started, Wicket itself is not yet started. Only after the first request, it passes through the WicketFilter and then Wicket starts itself up. However as I said this problem happened only once and I have been unable to reproduce this ever again.

  3. spring-projects-issues commented on Sep 7, 2015

    @spring-projects-issues
    CollaboratorAuthor
  4. spring-projects-issues commented on Sep 25, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Reopened since it may be covered along with #18071...

  5. added
    type: bug
    in: core
    on Jan 11, 2019
  6. added this to the 4.2.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions