NativeException cannot be cast to class java.lang.ThreadDeath

Hi Gang,

I am just after some help with a stacktrace please.
In that - I am not sure what is the end result of the error being reported?

(Please: put aside the cause of the error - I am just after the “What are the consequences”). Thanks!

Is it JUST an exception - whereby something failed , here’s a message about - let’s move on…

Or does it mean I now have a “zombie” thread?

As always - Thanks!

"ERROR","http-nio-8080-exec-4","12/19/2022","16:31:05","","class lucee.runtime.exp.NativeException cannot be cast to class java.lang.ThreadDeath (lucee.runtime.exp.NativeException is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @2d15e9b; java.lang.ThreadDeath is in module java.base of loader 'bootstrap');lucee.runtime.exp.NativeException: class lucee.runtime.exp.NativeException cannot be cast to class java.lang.ThreadDeath (lucee.runtime.exp.NativeException is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @2d15e9b; java.lang.ThreadDeath is in module java.base of loader 'bootstrap')
        at lucee.commons.lang.ExceptionUtil.rethrowIfNecessary(ExceptionUtil.java:200)
        at lucee.runtime.type.UDFImpl._call(UDFImpl.java:354)
        at lucee.runtime.type.UDFImpl.call(UDFImpl.java:223)
        at lucee.runtime.ComponentImpl._call(ComponentImpl.java:696)
        at lucee.runtime.ComponentImpl._call(ComponentImpl.java:584)
        at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1931)
        at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:787)
        at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1775)
        at scripts.verbatimdataloadrt_cfm$cf.call(/dbsetup/scripts/verbatimDataLoadRT.cfm:11)
        at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1056)
        at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:948)
        at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:219)
        at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
        at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2493)
        at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2478)
        at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2449)
        at lucee.runtime.engine.Request.exe(Request.java:45)
        at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1216)
        at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1162)
        at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
        at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:679)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassCastException: class lucee.runtime.exp.NativeException cannot be cast to class java.lang.ThreadDeath (lucee.runtime.exp.NativeException is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @2d15e9b; java.lang.ThreadDeath is in module java.base of loader 'bootstrap')
        ... 44 more

OS: Linux (5.4.0-1083-aws) 64bit
Java Version: 11:0:17+8
Tomcat Version: Apache Tomcat/8.5.39 (Ubuntu)
Lucee Version: Lucee 5.3.10.97

that’s a really odd caused by, @micstriit is looking into it.

can you file a bug plz?

The code in question is as follows:

	/**
	 * A java.lang.ThreadDeath must never be caught, so any catch(Throwable t) must go through this
	 * method in order to ensure that the throwable is not of type ThreadDeath
	 *
	 * @param t the thrown Throwable
	 */
	public static void rethrowIfNecessary(Throwable t) {
		if (unwrap(t) instanceof ThreadDeath) throw (ThreadDeath) t; // never catch a ThreadDeath
	}

At its core, the error is simply a bad assumption on the part of Lucee. Lucee thinks that any exception whose innermost root cause is of type ThreadDeath, can always be cast to a ThreadDeath. This is probably true in most cases just given how Lucee works, but you obviously found a way to generate an exception that was not a thread death that contained a threadDeath as the root cause. Lucee just needs to revisit its assumptions there IMO.

Not sure what you’re asking. It would appear a thread got killed to death for running too long. But then Lucee tripped over its feet when it tried to handle the resultant exception.

Well, you should probably be a little concerned about the fact that you have long-running threads that Lucee is trying to kill, but the errors in your OP is mostly just a bug in Lucee’s error handling.

Maybe, but not necessarily. The zombie thread issue used to be a thing with Tomcat’s HTTP connector where threads that were murdered to death didn’t always make it back into the thread pool. I haven’t heard of that happening in a while so I’m not sure if it’s still a thing.

Are you getting this error like all of a sudden all the time only on Lucee 5.4 specifically in such a way that makes you think it is a recent regression? Or is it just a one-off thing you ran across in the logs?

1 Like

good explanation @bdw429s

I created a ticket [LDEV-4335] - Lucee

2 Likes