tracker issue : CF-4202295

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

[ANeff] Bug for: NULL support removes return type check

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/Fixed

Reporter/Name(from Bugbase): Aaron Neff / ()

Created: 05/05/2018

Components: Language, Null Support

Versions: 2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2018.0.01.308605 (PreRelease) / 2018,0,0,309297

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Platforms All

Vote Count: 1

Issue: NULL support removes return type check

Repro:

1) enable NULL support via CF Admin or per-App setting, then run:

<cfscript>
  array function f1(){}
  f1()
  
  f2 = function() returntype="array" {}
  f2()
</cfscript>

Actual Result: blank page (and no return type check exceptions)

Expected Result: return type check exceptions

Attachments:

Comments:

Another: <cffunction name="f3" returntype="array"></cffunction> <cfset f3()> When NULL support enabled, then no return type check.
Comment by Aaron N.
27671 | May 05, 2018 12:17:11 AM GMT
Related thread: https://forums.adobeprerelease.com/coldfusionpr/discussion/380/cf-4202295-null-support-removes-return-type-check
Comment by Aaron N.
27672 | May 05, 2018 12:19:14 AM GMT
Hi Adobe, I see this is currently "To Test / NotABug" Huh? `array function f1(){}; f1();` currently throws no exception if NULL support is enabled. How is that not a bug? Thanks!, -Aaron
Comment by Aaron N.
27715 | May 08, 2018 06:44:53 AM GMT
Aaron, You argument is right when you say a function that specifies a returntype as array, needs to return an array (only), or throw an exception. However, with null support turned on, the value that's returned from the function when nothing is explicitly returned, is NULL.  For example, the following snippet would return [null].  <cffunction name="f3" returntype="array"></cffunction> <cfdump var="#f3()#"> This is an expected change in behavior when null support is turned on. 
Comment by Immanuel N.
27716 | May 08, 2018 07:15:11 AM GMT
Hi Immanuel, Returning NULL to represent the absence of a value is considered -bad practice-. Quote from Tony Hoare (https://en.wikipedia.org/wiki/Tony_Hoare), inventor of null reference: Speaking at a software conference called QCon London in 2009, he apologised for inventing the null reference: -------------------------------------------- "I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years." -------------------------------------------- Java 8 introduced java.util.Optional as a workaround. CF can LEARN from the past and NOT be lazy (i.e. copy that mistake). CF can be better than that, by making the right decision right now. The UDF signature must dictate what the UDF can return. If the return type can be optionally-enforced, then the signature needs to say that: Suggestions: - Allows NULL return: `public optional array function f(){}` - Disallows NULL return: `public array function f(){}` Or implement an actual Optional object. We could discuss various ways of implementing the current behavior, but it should not be the default. Thoughts? Thanks!, -Aaron
Comment by Aaron N.
27719 | May 08, 2018 10:34:42 PM GMT
Hi Adobe, This ticket could be marked fixed? B/c CF-4202355 is actually a duplicate of this one here.. Thanks!, -Aaron
Comment by Aaron N.
27779 | May 13, 2018 07:56:35 AM GMT
Marked as a duplicate. 
Comment by Immanuel N.
27780 | May 13, 2018 08:05:21 AM GMT
Hi Immanuel, Sorry if I was confusing.. _This_ (CF-4202295) is the original and was fixed. Vijay's comment on CF-4202355 should be copied to this one. CF-4202355 (for "?array" syntax) was, of course, not implemented. So, that CF-4202355 should be closed as duplicate of this original (CF-4202295) which *was* fixed. Could the status of both ticket please be flipped to remove any confusion as to what was fixed? Thanks!, -Aaron
Comment by Aaron N.
27913 | May 22, 2018 07:54:18 AM GMT
Updated the status. Marked as Fixed. 
Comment by Immanuel N.
27914 | May 22, 2018 08:06:00 AM GMT