nullpointerexception after calling non-cached udf attached to struct key that was created with objectload

Description

I went through the effort of making this easy to reproduce with standalone cfml example and ensuring I'm running latest version of lucee 4. This bug existed on Railo 4.2 too. I also determined that the bug is happening because the java property "this.properties.cachedWithin" is not null, and it should be null I guess since it's calling the wrong function, it should be calling _call on UDFImpl.java line 227 instead of the cachedWithin one. I don't understand how objectsave serializes internally, since it relies on quite a few classes, so I have given up trying to further understand how to patch it, for now. I assume that the issue is that objectsave is either not storing the null value, or objectload is not restoring it as null correctly. Hope this helps.

<cffunction name="function1" cachedwithin="request" localmode="modern" access="public">
<cfscript>
echo('cached function works<br />');
</cfscript>
</cffunction>
<cffunction name="function2" localmode="modern" access="public">
<cfscript>
echo('non-cached function does not work<br />');
</cfscript>
</cffunction>
<cffunction name="objectLoadBug" localmode="modern" access="public">
<cfscript>
path=request.zos.globals.privatehomedir;
request.runCount=0;
ts={
function1:function1,
function2:function2
};
objectsave(ts, path&"lucee.bin");

ns=objectload(path&"lucee.bin");

ns.function1();
try{
ns.function2();
}catch(Any e){
echo("Function can't run - NullPointerException because internal property cachedwithin is not null as it should be.");
writedump(e);
}
</cfscript>
</cffunction>
<cfscript>
objectLoadBug();
abort;
</cfscript>

Stacktrace:
java.lang.NullPointerException at lucee.runtime.type.UDFImpl._callCachedWithin(UDFImpl.java:239):239 at lucee.runtime.type.UDFImpl.call(UDFImpl.java:227):227 at lucee.runtime.type.util.StructSupport.call(StructSupport.java:254):254 at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742 at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1592):1592 at carlosring_com.test_cfm$cf.udfCall(/var/jetendo-server/jetendo/sites/carlosring_com/test.cfm:25):25 at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111 at lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328 at lucee.runtime.type.UDFImpl.call(UDFImpl.java:227):227 at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:766):766 at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742 at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1592):1592 at carlosring_com.test_cfm$cf.call(/var/jetendo-server/jetendo/sites/carlosring_com/test.cfm:33):33 at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:924):924 at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:857):857 at init.onrequest_cfm$cf.udfCall(/var/jetendo-server/jetendo/core/init/onRequest.cfm:66):66 at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111 at lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328 at lucee.runtime.type.UDFImpl.call(UDFImpl.java:227):227 at lucee.runtime.ComponentImpl._call(ComponentImpl.java:606):606 at lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524 at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1760):1760 at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:405):405 at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:221):221 at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:35):35 at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2264):2264 at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2227):2227 at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456 at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:47):47 at javax.servlet.http.HttpServlet.service(HttpServlet.java:729):729 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291):291 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239):239 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219):219 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106):106 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502):502 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142):142 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79):79 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88):88 at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676):676 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518):518 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091):1091 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668):668 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527):1527 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484):1484 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142):1142 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617):617 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61 at java.lang.Thread.run(Thread.java:745):745

Environment

tomcat 8, ubuntu 14, latest build of lucee 4 master github

Attachments

1

Activity

Bruce Kirkpatrick 
19 March 2016 at 20:28

You've made changes to the file since I sent my file.

There are still only 2 lines of code needing to change to fix this issue.
change:
cachedWithin = ExternalizableUtil.readString(in);
to:
cachedWithin = in.readObject();

and change:
ExternalizableUtil.writeString(out,Caster.toString(cachedWithin,null));
to
out.writeObject(cachedWithin);

verified this against the current version on Lucee5 github.

Bruce Kirkpatrick 
23 August 2015 at 00:56

I figured out how the serialization works with Externalize now. I've attached a proposed fix for this bug in UDFPropertiesImpl.java. It seems the empty string and use of writeString/readString is a problem for this particular code. I have changed it to writeObject/readObject so that both the long and string object types are able to be cast/restored automatically when coming back from serialization. This appears to be the simplest fix. My application is able to run with this patch build and the above code was able to run successfully. I also tested createTimespan and that still works too.

Sorry for not using pull request. Hope this helps.

Duplicate

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 22 August 2015 at 20:25
Updated 19 December 2016 at 19:01
Resolved 19 December 2016 at 19:01