Date function stopped working after 9.7.2 update?

After upgrading Katalon to version 9.7.2 all my tests that uses the following Date function stopped workin.

is this function deprecated or stopped working?

What’s another simple function i can use in replacement?
image

error:

Reason:

groovy.lang.MissingMethodException: No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [MM/dd/yyyy]

Possible solutions: from(java.time.Instant), stream(), toYear(), getAt(java.lang.String), parse(java.lang.String), print(java.io.PrintWriter)
2 Likes

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

import java.text.SimpleDateFormat

def now = new SimpleDateFormat(“MM/dd/yyyy”).format(new Date())
println(“now = $now”)

can you please try this one.

kindly add little more information like logs or error trace if you ran the date function?

1 Like

na, same error.
I think the new update screwed something up.

1 Like

The above should have the same issue as what you were originally using. I learned Java decades ago, so I also have to update my Java/Groovy knowledge for my scripts. Here is what I use for the dates now:

import java.time.format.DateTimeFormatter
import java.time.LocalDate

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy")

LocalDate todaysDate = LocalDate.now();
def yesterdayDate = todaysDate.minusDays(1).format(formatter)
def  tomorrowDate = todaysDate.plusDays(1).format(formatter)

There is plusMonths, minusMonths, plusYears and minusYears. And you can create multiple DateTimeFormatters for the different formats within your application.

I could reproduce the incident: the new Date().format('MM/dd/yyyy') is displayed with an underline, which indicates a coding mistake.

Let me report how I reproduced it.

environment

I reproduced it using

  • macOSX 14.6.1
  • Katalon Studio v9.0.0 (Free)

The Test Case scripts I tried

Test Cases/printGroovyVersion:

public String getGroovyVersion() {
        try {
                return org.codehaus.groovy.runtime.InvokerHelper.version
        }
        catch (Throwable ignore) { }
        return GroovySystem.version
}

println getGroovyVersion()

When I ran it, it printed:

2024-09-21 09:01:41.933 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-09-21 09:01:41.936 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/PrintGroovyVersion
2024-09-21 09:01:42.493 DEBUG testcase.PrintGroovyVersion              - 1: println(getGroovyVersion())
2024-09-21 09:01:42.507 DEBUG testcase.PrintGroovyVersion              - 1: try
2024-09-21 09:01:42.516 DEBUG testcase.PrintGroovyVersion              - 1: return org.codehaus.groovy.runtime.InvokerHelper.version
2024-09-21 09:01:42.573 DEBUG testcase.PrintGroovyVersion              - 2: catch (Throwable ignore)
2024-09-21 09:01:42.588 DEBUG testcase.PrintGroovyVersion              - 4: return groovy.lang.GroovySystem.version
3.0.17
2024-09-21 09:01:42.687 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/PrintGroovyVersion

Test Cases/TryDateFormat

def now = new Date().format('MM/dd/yyyy')
println "now = $now"

Normal case

I tried to run the TryDateFormat in a healty Katalon Studio v9.0.0. It ran just fine. I could see in the console:

2024-09-21 09:09:33.075 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-09-21 09:09:33.080 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TryDateFormat
2024-09-21 09:09:33.853 DEBUG testcase.TryDateFormat                   - 1: now = Date().format("MM/dd/yyyy")
2024-09-21 09:09:33.900 DEBUG testcase.TryDateFormat                   - 2: println(now = $now)
now = 09/21/2024
2024-09-21 09:09:34.097 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TryDateFormat

Problem reproduced

I checked the list of the jars of Groovy language bundled in the Katalon Studio v9.0.0 on macOS.

$ pwd
/Applications/Katalon Studio.app
:/Applications/Katalon Studio.app
$ ls -la Contents/Eclipse/configuration/resources/lib | grep groovy
-rwxr-xr-x@  1 kazuakiurayama  admin     82789 10 24  2023 groovy-ant-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin      6181 10 24  2023 groovy-astbuilder-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     60564 10 24  2023 groovy-cli-picocli-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin   1556615 10 24  2023 groovy-console-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     15178 10 24  2023 groovy-datetime-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin      7405 10 24  2023 groovy-dateutil-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    122803 10 24  2023 groovy-docgenerator-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    161394 10 24  2023 groovy-groovydoc-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    992265 10 24  2023 groovy-groovysh-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    132953 10 24  2023 groovy-jmx-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    128879 10 24  2023 groovy-json-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     16838 10 24  2023 groovy-jsr223-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    233320 10 24  2023 groovy-macro-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     29430 10 24  2023 groovy-nio-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     22733 10 24  2023 groovy-servlet-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     78915 10 24  2023 groovy-sql-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    429066 10 24  2023 groovy-swing-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin     94160 10 24  2023 groovy-templates-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    118019 10 24  2023 groovy-test-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin      9118 10 24  2023 groovy-test-junit5-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin      5484 10 24  2023 groovy-testng-3.0.17.jar
-rwxr-xr-x@  1 kazuakiurayama  admin    291717 10 24  2023 groovy-xml-3.0.17.jar

Intentionally, I removed the groovy-dateutil-3.0.17.jar

$ rm Contents/Eclipse/configuration/resources/lib/groovy-dateutil-3.0.17.jar 

I stopped the Katalon Studio and restarted it. Then I could see the format method of Date object is underlined. The Test Cases/TryDateFormat failed with an Exception.

The incident was reproduced when the groovy-dateutil jar got missing out of the runtime classpath of Katalon Studio.

1 Like

@ashraf.madina

Possibly, your Katalon Studio installation is broken: the groovy-datetime jar is missing out of the runtime classpath.

Could you check if the groovy-datetime jar is found or not in the Katalon installation folder Contents/Eclipse/configuration/resources/lib of yours?

I am not sure why your Katalon Studio’s intallation was broken.

Did you used the in-app update?

The “in-app update” of Katalon Studio is known to be buggy. You should not use it.

You should re-install Katalno Studio cleanly. That’s the only thing you could try to fix your problem. Remove the previous installation first, then re-install it. Please make sure that the groovy-dateutil jar is installed in the expected location

1 Like

The Date class of Java language does not implement format(String) method at all. See the JDK17 Javadoc

The Date.format(String) method is provided by Groovy language as an enhancement to the java.util.Date class. See the Groovy’s doc.

For your reference, see the following Groovy documation “Groovy Dates and Times Cheat Sheet”

Groovy’s enhancements for the legacy date classes are in the groovy-dateutil module (prior to Groovy 2.5, this functionality was built in to the core module).

Now, the above article told me that the format(String) is provided in the groovy-dateutil jar in the Groovy v3 and higher. Therefore I thought I would be able to reproduce the original poster’s incident by removing the groovy-dateutil jar out of the Katalon Studio’s runntime classpath. I tried it; and I could successfully reproduce the incident.

I would conclude that the @ashraf.madina has Katalon Studio installed broken somehow.

1 Like

I could recall an old discussion in Jan 2021:

In the version7.9-rc Katalon team tried to upgrade the bundled Groovy language from v2.4 to v3. This release-candiate gave us a lot of problems, which included the problem of new Date().format(string).

Now the problem revived for @ashraf.madina in the v9.7.2. It seems to be recuring in any versions of Katalon Studio.

1 Like

I regret that the Katalon Studio product is fragile in managing external dependencies. KS seems to have no robust capability of managing the external dependencies.

Today I witnessed, my Katalon Studio v9.0 performed no self-check even if a required groovy-*.jar is missingin the runtime classpath. Katalon Studio just let users encounter problems. In future, poor users will report the similar problems again and again in this User forum.

I think that users should be skeptical of Katalon’s capability of managing external dependencies to be consistent. By the way, Katalon has announced v10 is to be release soon. I am afraid that this upgrade may cause some problems in managing external dependencies.

2 Likes

how do you add back this jar file to katlaon studio

1 Like

I re-installed Katalon Studio v9.0.0 using the .dmg file downloaded from Katalon.

I checked the 9.7.2 version of Katalon, and the groovy .jars are totally differently handled than before. There is only one groovy fat .jar file instead of the multiple files in previous versions (for example 9.7.0.).

It is hard to tell which files are missing in this which was involved in the previous versions. Potentially more files could be missing.

Good point. Katalon team must have made a mistake in creating the fat jar.

Likely.

It seems that the v9.7.2 is not tested enough.

@Elly_Tran

I would pass this issue to Katalon team.

Hi,

I have created a ticket to investigate it. Thank you!

I compared the jars contained in the v9.7.2 and v9.0.0.

I believe that I have found out what mistake Katalon team has made. Let me report it.

What I observed

Jars contained in v9.0.0

v9.0.0 contained 2 jars: groovy-datetime-3.0.17.jar and groovy-dateutil-3.0.17.jar.

Both jars contained a file with the same path
META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule.

The content of 2 ExtensionModule files are silightly different.

The groovy-datetime-*.jar has the ExtensionModule file that declares:

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateTimeStaticExtensions

The groovy-dateutil-*.jar has the ExtesionModule file that declares:

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateUtilStaticExtensions

Jar contained in v9.7.2

v9.7.2 containd a jar groovy-3.0.17-fat.jar.

The fat.jar contained a file of path META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule, which declares:

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateTimeStaticExtensions

Problem

v9.7.2 misses a META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule file that declares

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateUtilStaticExtensions
1 Like

What is the META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule file?

See the Groovy’s document:

https://groovy-lang.org/metaprogramming.html#module-descriptor

For Groovy to be able to load your extension methods, you must declare your extension helper classes. You must create a file named org.codehaus.groovy.runtime.ExtensionModule into the META-INF/groovy directory:

Only when the ExtentionModule file declares

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateUtilStaticExtensions

, the Date.format(String) will work. Without this META-INF in the runtime classpath, the format method will be underlined as the original poster reported.

A possible fix

Groovy accepts a comma-sperated list of class names, as follows:

staticExtensionClasses=org.apache.groovy.datetime.extensions.DateTimeStaticExtensions,org.apache.groovy.datetime.extensions.DateUtilStaticExtensions,...(a lot more class names)

Katalon had to generate a ExtensionMadule file that enumerates all “static extension classes” out of the component groovy-*-3.0.17.jar files.

I am afraid that Katalon team was careless in introducing the fat.jar in v9.7.2. I wonder why they made such a risky change casually.

  • I guess, they have never read the Groovy’s document; they do not know what ‘ExtensionModule’ file is.

  • I guess, Katalon team do not understand how Date.format(String) is implemented.

So they took it easy; they modified their build script to merge all groovy-*-3.0.17.jar files into a fat jar file while they did not care how the resulting
META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule
file should be.

This incident indicates that Katalon team released the Katalon Studio v9.7.2 without testing it enough. I would advise users not to touch it.

Hi,

We have acknowledged this issue and would like to suggest a workaround in the video recording below. Simply add this jar groovy-dateutil-3.0.17.jar (7.2 KB) into external library. Let me know if it works/ not work!

1 Like