tracker issue : CF-4126264

select a category, or use search below
(searches all categories and all time range)
Title:

serializeJson on ORM entity throws a runtime NullPointerException in some cases.

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Geoffrey Demoulin / Geoffrey Demoulin (Geoffrey Demoulin)

Created: 03/08/2016

Components: Language, Serialization

Versions: 11.0

Failure Type: Crash

Found In Build/Fixed In Build: CF11_Final / 2016

Priority/Frequency: Critical / Some users will encounter

Locale/System: English / Windows 8.1/64bit

Vote Count: 1

Problem Description:

When trying to serialize an ORM entity to Json, a NullPointerException is thrown in specific situations.

To test, I have an extremely simple database with the following tables:

Delivery -> Package <-> PackageOrder -> Order

Delivery:
  id

Package:
  id
  deliveryId

PackageOrder:
  orderId
  packageId

Order:
  id

The Order entity has an extra field computed at runtime (persistent="false") with a custom getter:

	property name="hashid" type="string" setter="false" persistent="false";

	public string function getHashid(){
		return "COMPUTED" & variables.id;
	}

When using the following code, the crash happens:

	public any function getObjectToSerialize(){
		var delivery = entityLoadByPK("Delivery", 1);
		var obj = delivery.getPackages()[1].getPackagedOrders()[1].getOrder();
		return obj;
	}

	// Somewhere else:
	try{
		WriteDump(var=serializeJSON(getObjectToSerialize()), abort=true); // NullPointerException
	}catch(any e){
		WriteDump(var=e, abort=true);
	}

Dumping the entity returned by getObjectToSerialize is working as intended.

The stack is available in the notes below.

Interestingly, deleting the custom getHashid getter will prevent the error from happening.




Steps to Reproduce:

Use the application in the attached zip.




Actual Result:

NullPointerException




Expected Result:

A Json representation of the entity




Any Workarounds:
N/A

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4126264

External Customer Info:
External Company:  
External Customer Name: Geoffrey Demoulin
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

  1. March 09, 2016 00:00:00: 1_test_case.zip

Comments:

java.lang.RuntimeException: java.lang.NullPointerException at coldfusion.runtime.JSONUtils.getCFCDataAsMap(JSONUtils.java:761) at coldfusion.runtime.JSONUtils.serializeJSONProxy(JSONUtils.java:611) at coldfusion.runtime.JSONUtils.serializeJSONBase(JSONUtils.java:390) at coldfusion.runtime.JSONUtils.serializeJSON(JSONUtils.java:146) at coldfusion.runtime.JSONUtils.serializeJSON(JSONUtils.java:121) at coldfusion.runtime.JSONUtils.serializeJSON(JSONUtils.java:108) at coldfusion.runtime.CFPage.SerializeJSON(CFPage.java:8092) at cfindex2ecfm832620916.runPage(D:\src\Projects\test.local\index.cfm:12) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:246) at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:736) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:572) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2991) at cfapplication2ecfc853940087$funcONREQUEST.runFunction(D:\src\Projects\test.local\application.cfc:40) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:487) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:420) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:383) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:334) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:231) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:643) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:432) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:402) at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:108) at coldfusion.runtime.AppEventInvoker.onRequest(AppEventInvoker.java:301) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:462) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:142) at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.CfmServlet.service(CfmServlet.java:219) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [...]
Comment by External U.
4362 | March 08, 2016 09:59:48 PM GMT
[...] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:422) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:199) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException
Comment by External U.
4363 | March 08, 2016 09:59:53 PM GMT
Any news on this bug? The test case provided should be all that is needed to reproduce the issue.
Comment by External U.
4364 | June 10, 2016 12:54:15 AM GMT
Hi Geoffrey, We did try out the test case you provided. Thanks for the extensive information provided. We were however unable to repro this issue on CF 2016, or CF 11 with Update 9 applied. No exceptions were thrown even when the getHashid() method was invoked. Could you please confirm the hotfix version applied on the server? - Immanuel
Comment by Immanuel N.
4365 | June 13, 2016 04:29:03 AM GMT
Hi Immanuel, I'm currently running cf11u8, which I believe is the latest publicly available patch.
Comment by External U.
4366 | June 13, 2016 05:51:40 PM GMT
The update 9 for cf11 popped up this morning and I installed it. This installation of ColdFusion is also new since I changed my computer recently. I am now running windows 10/x64. Unfortunately the issue persists. You mentioned that no error occurred when you tested, does this means that you got the dump of the serialized object?
Comment by External U.
4367 | June 14, 2016 07:55:40 PM GMT
Geoffrey, I dint see the issue since the CFC loads only for the first invocation in the example. Altered the example slightly, added ormreload() and we see the issue. Thanks for raising this. I can confirm the issue does not exist on CF 2016. Will be tracking this for CF 11 and CF 10. - Immanuel
Comment by Immanuel N.
4368 | June 16, 2016 02:15:35 AM GMT
This is fixed in 2016. We will evaluate to see if the fix can be back-ported to earlier versions.
Comment by Vamseekrishna N.
4369 | August 03, 2016 03:31:53 AM GMT
We have just encountered this after "upgrading" from ACF10 (where this worked correctly). Could you update this ticket with a justification for why this could not be fixed in a supported product?
Comment by Samuel K.
4370 | April 24, 2017 08:42:36 PM GMT
This fix will be backported to 11.0 and will be made available in the next bug-fix update release for 11.0
Comment by Vamseekrishna N.
4371 | September 14, 2017 04:10:42 PM GMT