Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal reflective access on shutdown of ExecutorService #22939

Closed
Clank84 opened this issue May 9, 2019 · 0 comments
Closed

Illegal reflective access on shutdown of ExecutorService #22939

Clank84 opened this issue May 9, 2019 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@Clank84
Copy link

Clank84 commented May 9, 2019

Affects: spring-core-5.1.6.RELEASE

I'm migrating an application to Open JDK 11.0.2, and updated its Spring Boot from v1.5 to v2.1.4, that in turn updates SpringFramework to v5.1.6. My application runs several threads, and I implemented an EventListener for the situation when an administrator shuts down the application and the Context is stopped or closed the application tries to gracefully shutdown the child threads managed by an ExecutorService.

@Component
public class AppController {

  @Autowired
  private ExecutorService runner1;

  public void run(ApplicationArguments theArgs) throws Exception {

    Runnable myRunnable = new Consumer();

    runner1.execute(myRunnable);

    //Do Business Logic, until Thread Interrupted

    runner1.shutdown();
    if (!runner1.awaitTermination(5, TimeUnit.SECONDS)) {
      runner1.shutdownNow();
    }
    System.exit(2);
  }
}

Good news is that everything shuts down. But I do get the following warning with JDK 11:

Illegal reflective access by org.springframework.util.ReflectionUtils (file:spring-core-5.1.6.RELEASE.jar) 
to method java.util.concurrent.Executors$DelegatedExecutorService.shutdown()

My problem appears similar to Issues #22791 and #22242. I've attached a sample project to recreate the error when you use JDK 11, just run the included JUnit class and use the VM arg --illegal-access=debug to see the stacktrace.

WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:spring-core-5.1.6.RELEASE.jar) to method java.util.concurrent.Executors$DelegatedExecutorService.shutdown()
        at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:602)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:336)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:271)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1055)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1062)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1057)
        at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1026)
        at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:945)

reflective-access-threads.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 9, 2019
@jhoeller jhoeller self-assigned this May 9, 2019
@jhoeller jhoeller added this to the 5.2 M3 milestone May 9, 2019
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 9, 2019
@jhoeller jhoeller modified the milestones: 5.2 M3, 5.1.8 Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants