jetty / jetty/jetty.project

LifeCycle.Listener events are not executed on the classloader that the Listener was created on.

Open
#13,310 2 comments 0 reactions 1 assignee Claimed by @joakime View on GitHub
Enhancement
Dominant language
Java
Stars
4.1k
Forks
2k
Avg merge
3d 56m
Merged PRs (30d)
48

Description

**Jetty version(s)**
12.x

**Enhancement Description**
If you have a `LifeCycle.Listener` implementation that is created in an environment, and added to the `Server.addEventListeners()` location, then there's an undesired side effect.

Assume we have a class `org.example.DemoService` that implements `LifeCycle.Listener`.
It has the following XML for jetty start.

``` xml





```

The XML is called from a `demoservice.mod` with the following contents.

```
[environment]
ee8

[lib]
lib/demo/demoservice-1.jar

[xml]
etc/demoservice.xml
```

When the `DemoService` instance is created, by `XmlConfiguration`, it is created against the EE8 `Environment.getClassLoader()` (which is a URLClassLoader).

But when the `DemoService.lifeCycleStarting(Event)` executes, it's being called with a `Thread.currentThread().getContextClassLoader()` which belongs to the Jetty server's `startJarLoader@694f9431` (which is the classloader created by jetty-start).

The calls to `lifeCycleStarting(Event)` should have the Thread context classloader which is the same classloader that was used to create the instance of `DemoService` itself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.