reReplace NullPointer Exception - Lucee-6

I am getting an intermittent NullPointer on reReplace.

fileSep is one of these characters: \ / .

return reReplace(path, “[\/]+”, fileSep, “all”);

I reviewed the Lucee code and it is crashing on

[Lucee/core/src/main/java/lucee/runtime/functions/string/REReplace.java at 6.2 · lucee/Lucee · GitHub](https://RERelace.java on line 48)

I noticed the code on line 48 is different then the line 43.

OS: Windows 10
Java Version: OpenJDK 64-Bit Server VM Temurin-17.0.10+7 (build 17.0.10+7, mixed mode, sharing)
Servlet Version: Jetty 10
Lucee Version: Lucee 6.1.0.243

ucee.runtime.exp.NativeException: java.lang.NullPointerException at lucee.runtime.functions.string.REReplace.call(REReplace.java:48) at boaz.sitemgr_cfc$cf.udfCall6(/boaz/siteMgr.cfc:871) at boaz.sitemgr_cfc$cf.udfCall(/boaz/siteMgr.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:715) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:588) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:2029) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.processor_cfc$cf.udfCall1(/boaz/processor.cfc:290) at boaz.processor_cfc$cf.udfCall(/boaz/processor.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:782) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.processor_cfc$cf.udfCall1(/boaz/processor.cfc:244) at boaz.processor_cfc$cf.udfCall(/boaz/processor.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:782) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.processor_cfc$cf.udfCall1(/boaz/processor.cfc:133) at boaz.processor_cfc$cf.udfCall(/boaz/processor.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:782) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.processor_cfc$cf.udfCall1(/boaz/processor.cfc:60) at boaz.processor_cfc$cf.udfCall(/boaz/processor.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:715) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:588) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:2029) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.response_cfc$cf.udfCall1(/boaz/response.cfc:112) at boaz.response_cfc$cf.udfCall(/boaz/response.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:715) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:588) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:2029) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at boaz.boaz_cfc$cf.udfCall1(/boaz/boaz.cfc:201) at boaz.boaz_cfc$cf.udfCall(/boaz/boaz.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:715) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:588) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:2029) at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:476) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:212) at lucee.runtime.listener.ModernAppListener.onRequest(ModernAppListener.java:100) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2731) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2718) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2689) at lucee.runtime.engine.Request.exe(Request.java:45) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1155) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1112) 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:590) at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1410) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:529) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:598) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1580) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1553) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:192) at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:301) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.server.Server.handle(Server.java:563) at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501) at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:461) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.produce(AdaptiveExecutionStrategy.java:193) at org.eclipse.jetty.http2.HTTP2Connection.produce(HTTP2Connection.java:208) at org.eclipse.jetty.http2.server.HTTP2ServerConnection.onOpen(HTTP2ServerConnection.java:116) at org.eclipse.jetty.io.AbstractEndPoint.upgrade(AbstractEndPoint.java:451) at org.eclipse.jetty.server.NegotiatingServerConnection.onFillable(NegotiatingServerConnection.java:125) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100) at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:558) at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:379) at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:146) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100) at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.lang.NullPointerException … 120 more

I reviewed the code on:

  • reFind
  • reFindNoCase
  • reMatch
  • reMatchNoCase
  • reReplace
  • reReplaceNoCase

reReplace and reReplaceNoCase are coded different then the rest when it comes to use of pc ( page context )

Regex regex = ((PageContextImpl) ThreadLocalPageContext.get()).getRegex();

vs

Regex regex = ((PageContextImpl) pc).getRegex();

@micstriit @Igal - My knowledge of Java is limited though I have written a few things in Java over the years. This issue listed above is related to how ThreadLocalPageContext.get() works. I submitted a pull request for reReplace and reReplaceNoCase which I am sure needs help.

This did solve my reReplace issue but I then ran into another ThreadLocalPageContext.get() null pointer issue.

Lucee 6.1.0.243
Jetty 10 - because I can’t upgrade to 12 until this Lucee 6 question is fixed.
Windows 10 & Arch Linux latest.

1 Like