Skip to main content
Participant
October 28, 2021
Answered

CF2021 BUG? Parameter validation error for the DATEFORMAT function only for 01/01/1982

  • October 28, 2021
  • 2 replies
  • 544 views

ColdFusion 2021 Update 2 (2021.0.02.328618) WINx64

Java VM Version 11.0.11+9-LTS-194 

 

<cfoutput>

#DateFormat("01/01/1982","dd-Mmm-yyyy")#

</cfoutput>

 

Thrown the same error with "01-Jan-1982" and all different date format for 01/01/1982.

No issue for dates like 02/01/1982, 01/01/1981, etc.

 

Had tried to run the same code on cffidle.org but no error was thrown.

A quick check was that cffidle was running on Linux while mine was on Windows.

 

The error is as below: -

 

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.


The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Parameter validation error for the DATEFORMAT function.

The value of parameter 1, which is currently 01/01/1982, must be a class java.util.Date value.
 
The error occurred in D:/wwwroot/test_cf2021_date.cfm: line 3
1 : <cfoutput>
2 : 
3 : #DateFormat("01/01/1982","dd-Mmm-yyyy")#
4 : 
5 : </cfoutput>

Resources:

 

Browser  Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.30
Remote Address  192.168.190.164
Referrer   
Date/Time  28-Oct-21 02:13 PM
Stack Trace


coldfusion.compiler.validation.IllegalFuncArgumentException: Parameter validation error for the DATEFORMAT function.
	at coldfusion.compiler.validation.FunctionValidator.checkArgument(FunctionValidator.java:135)
	at coldfusion.compiler.validation.CFMLCodeValidator.visit(CFMLCodeValidator.java:268)
	at coldfusion.compiler.ASTfuncparams.accept(ASTfuncparams.java:75)
	at coldfusion.compiler.ASTruntimeCall.accept(ASTruntimeCall.java:470)
	at coldfusion.compiler.Node.walkChildren(Node.java:405)
	at coldfusion.compiler.ASTevalcfoutput.accept(ASTevalcfoutput.java:21)
	at coldfusion.compiler.Node.walkChildren(Node.java:405)
	at coldfusion.compiler.ASTcftag.accept(ASTcftag.java:70)
	at coldfusion.compiler.Node.walkChildren(Node.java:405)
	at coldfusion.compiler.ASTstart.accept(ASTstart.java:122)
	at coldfusion.compiler.NeoTranslator.validate(NeoTranslator.java:603)
	at coldfusion.compiler.NeoTranslator.parseAndTransform(NeoTranslator.java:470)
	at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:407)
	at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:160)
	at coldfusion.runtime.TemplateClassLoader$TemplateCache$1.fetch(TemplateClassLoader.java:533)
	at coldfusion.util.LruCache.get(LruCache.java:180)
	at coldfusion.runtime.TemplateClassLoader$TemplateCache.fetchSerial(TemplateClassLoader.java:453)
	at coldfusion.util.AbstractCache.fetch(AbstractCache.java:58)
	at coldfusion.util.SoftCache.get_statsOff(SoftCache.java:153)
	at coldfusion.util.SoftCache.get(SoftCache.java:92)
	at coldfusion.runtime.TemplateClassLoader.findClass(TemplateClassLoader.java:734)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:145)
	at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
	at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:97)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:81)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
	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:231)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:228)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.ha.session.JvmRouteBinderValve.invoke(JvmRouteBinderValve.java:182)
	at org.apache.catalina.ha.tcp.ReplicationValve.invoke(ReplicationValve.java:329)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:373)
	at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:462)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723)
	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:834)
    This topic has been closed for replies.
    Correct answer BKBK
     

    The DateFormat is working when using LSparseDateTime; but not when using parseDateTime.


    By @Tan Wee Han

     

    Thanks for sharing that, @Tan Wee Han . I am not surprised that you can still get an error. The reason is the same as the one I explained before.

     

    When you request ColdFusion to cast from string to date, as LSparsedatetime and parsedatetime do, there is always a risk. ColdFusion might not recognize the string as a valid date. Whether or not the string is a valid date  depends on a number of factors, the commonest being the ColdFusion version, the Java version on which ColdFusion is running, the Locale, and the encoding.

     

    Which is why there are functions to test whether a string is a valid representation of a date. The idea is that you test the string first.

    <cfoutput>
    	isValid("date", "01/01/1982"): #isValid("date", "01/01/1982")# <br>
    	isValid("date", "1/1/1982"): #isValid("date", "1/1/1982")# <br>
    	isDate("01/01/1982"): #isDate("01/01/1982")# <br>
    	isDate("1/1/1982"): #isDate("1/1/1982")# <br><br>
    	Locale: #getLocale()# <br>
    	LSisDate("01/01/1982"): #LSisDate("01/01/1982")# <br>
    	LSisDate("1/1/1982"): #LSisDate("1/1/1982")# <br>
    </cfoutput>

     

    If you get a yes, then it will probably be safe to assume ColdFusion can cast the string to a date. As you can see, I said probably.

     

    If you want 100% reliability, then avoid representing dates as strings. Use instead createdate or createdatetime.

    <cfset dateObject=createdate(1982,1,1)>
    <!--- Alternative --->
    <!---<cfset dateObject=createdatetime(1982,1,1,0,0,0)>--->
    <cfoutput>
    #DateFormat(dateObject,"dd-Mmm-yyyy")#
    </cfoutput>

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 29, 2021

    Though ColdFusion is weakly-typed, there are times when it enforces the rules strictly.  You got the error because your code is not quite correct. In fact, ColdFusion tells you precisely why: "The value of parameter 1, which is currently 01/01/1982, must be a class java.util.Date value." In other words, you have used a string as the first argument, but the correct type to use is a date object.

     

    ColdFusion will often do its best to cast a non-date argument (in this case, a string) to a date. Sometimes it can't, such as in this case. I suspect that ColdFusion had trouble casting "01/01/1982" to a date. The result is then a parameter validation error.

     

    Suggestion: 

     

    <cfset dateObject=parseDatetime("01/01/1982")>
    
    <!--- Alternative, based on your locale --->
    <!---<cfset dateObject=LSparseDatetime("01/01/1982")>--->
    
    <cfoutput>
    #DateFormat(dateObject,"dd-Mmm-yyyy")#
    </cfoutput>

     

     

     

     

     

    Participant
    October 30, 2021

    The DateFormat is working when using LSparseDateTime; but not when using parseDateTime.

    Thanks.

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    October 30, 2021
     

    The DateFormat is working when using LSparseDateTime; but not when using parseDateTime.


    By @Tan Wee Han

     

    Thanks for sharing that, @Tan Wee Han . I am not surprised that you can still get an error. The reason is the same as the one I explained before.

     

    When you request ColdFusion to cast from string to date, as LSparsedatetime and parsedatetime do, there is always a risk. ColdFusion might not recognize the string as a valid date. Whether or not the string is a valid date  depends on a number of factors, the commonest being the ColdFusion version, the Java version on which ColdFusion is running, the Locale, and the encoding.

     

    Which is why there are functions to test whether a string is a valid representation of a date. The idea is that you test the string first.

    <cfoutput>
    	isValid("date", "01/01/1982"): #isValid("date", "01/01/1982")# <br>
    	isValid("date", "1/1/1982"): #isValid("date", "1/1/1982")# <br>
    	isDate("01/01/1982"): #isDate("01/01/1982")# <br>
    	isDate("1/1/1982"): #isDate("1/1/1982")# <br><br>
    	Locale: #getLocale()# <br>
    	LSisDate("01/01/1982"): #LSisDate("01/01/1982")# <br>
    	LSisDate("1/1/1982"): #LSisDate("1/1/1982")# <br>
    </cfoutput>

     

    If you get a yes, then it will probably be safe to assume ColdFusion can cast the string to a date. As you can see, I said probably.

     

    If you want 100% reliability, then avoid representing dates as strings. Use instead createdate or createdatetime.

    <cfset dateObject=createdate(1982,1,1)>
    <!--- Alternative --->
    <!---<cfset dateObject=createdatetime(1982,1,1,0,0,0)>--->
    <cfoutput>
    #DateFormat(dateObject,"dd-Mmm-yyyy")#
    </cfoutput>
    James Moberg
    Inspiring
    October 28, 2021

    I tested on TryCF.com (which has more CF versions to test) and it worked without throwing an error.

     

    I wonder if the problem is the mask.  Is there any reason you aren't using the "dd-mmm-yyyy" syntax?

     

    Please note that capital letters may mean something else as Adobe changed how things work in late 2020.

    https://helpx.adobe.com/coldfusion/kb/dateformat-function-coldfusion-2021.html 

    • M: Month in year.
    • 😧 Day in year.

     

    Also: CF2016u3 (Oct 2016) added some additional masks:

    • e/E: Day in a week.
    • f/F: Day of a week in a month.
    • k/K: Hour in a day (1-24).
    • w: Week of the year as digit.
    • ww: Week of the year as digits. Leading zero for single-digit week.