Skip to content

Commit 6c22648

Browse files
authored
12.0.x: warn the first time the TCCL fails to be set (#13842)
warn the first time the TCCL fails to be set Signed-off-by: Ludovic Orban <[email protected]>
1 parent 9b54bfe commit 6c22648

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Objects;
2929
import java.util.Set;
3030
import java.util.concurrent.CopyOnWriteArrayList;
31+
import java.util.concurrent.atomic.AtomicBoolean;
3132
import java.util.concurrent.atomic.AtomicReference;
3233
import java.util.function.Consumer;
3334
import java.util.function.Predicate;
@@ -133,6 +134,7 @@ public static ContextHandler getContextHandler(Request request)
133134
private final MimeTypes.Wrapper _mimeTypes = new MimeTypes.Wrapper();
134135
private final List<ContextScopeListener> _contextListeners = new CopyOnWriteArrayList<>();
135136
private final List<VHost> _vhosts = new ArrayList<>();
137+
private final AtomicBoolean _enterScopeSetClassloaderFailed = new AtomicBoolean();
136138

137139
private String _displayName;
138140
private String _contextPath = "/";
@@ -634,8 +636,12 @@ protected ClassLoader enterScope(Request contextRequest)
634636
}
635637
catch (Throwable x)
636638
{
637-
if (LOG.isDebugEnabled())
638-
LOG.debug("error setting a context classloader on thread {}", Thread.currentThread(), x);
639+
// Log as warning the first time it happens.
640+
String msg = "Error setting a context classloader on thread {}";
641+
if (_enterScopeSetClassloaderFailed.compareAndSet(false, true))
642+
LOG.warn(msg, Thread.currentThread(), x);
643+
else if (LOG.isDebugEnabled())
644+
LOG.debug(msg, Thread.currentThread(), x);
639645
}
640646
}
641647
notifyEnterScope(contextRequest);

jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public boolean handle(Request request, Response response, Callback callback) thr
193193
@Override
194194
public void run()
195195
{
196-
try (Blocker.Callback cb = Blocker.callback())
196+
try (StacklessLogging ignore = new StacklessLogging(ContextHandler.class);
197+
Blocker.Callback cb = Blocker.callback())
197198
{
198199
// When a classloader is configured, Response.write() tries to set it as the context classloader.
199200
response.write(true, ByteBuffer.allocate(32), cb);
@@ -209,6 +210,12 @@ public void run()
209210
}
210211
}
211212

213+
@Override
214+
public ClassLoader getContextClassLoader()
215+
{
216+
return null;
217+
}
218+
212219
@Override
213220
public void setContextClassLoader(ClassLoader cl)
214221
{
@@ -258,7 +265,8 @@ public boolean handle(Request request, Response response, Callback callback) thr
258265
@Override
259266
public void completed(Integer result, Object attachment)
260267
{
261-
try (Blocker.Callback cb = Blocker.callback())
268+
try (StacklessLogging ignore = new StacklessLogging(ContextHandler.class);
269+
Blocker.Callback cb = Blocker.callback())
262270
{
263271
// When a classloader is configured, Response.write() tries to set it as the context classloader.
264272
response.write(true, ByteBuffer.allocate(32), cb);

0 commit comments

Comments
 (0)