Reason: BUG! exception in phase 'semantic analysis' in source unit


#1

The below simple line of code is failing in Katalon v5.9, v5.9.1, v5.10 (Beta), but works fine in v7.1

Katalon team … Could you please explain why ??? is this happening. I want to correct myself :grinning:

But this :imp: issue really screwed me up for more than a week.

To solve this issue, remove static from the method.

import java.text.SimpleDateFormat as SimpleDateFormat

System.err.println datefnWithTime()

static String datefnWithTime() {
String pattern = “dd-MMM-yyyy hh:mm:ss”
SimpleDateFormat format = new SimpleDateFormat(pattern)
return format.format(new Date())
}

while copy pasting this piece of code, delete the double quote and type again “dd-MMM-yyyy hh:mm:ss”


#2

Let me explain what I have done, what I think.

I made a 15451.groovy file which contains just the same lines as you presented above. And I executed it with groovy command in command-line.

kazurayam@N01-0370 MINGW64 ~/tmp
$ cat 15451.groovy
import java.text.SimpleDateFormat as SimpleDateFormat

System.err.println datefnWithTime()

static String datefnWithTime() {
       String pattern = "dd-MMM-yyyy hh:mm:ss"
       SimpleDateFormat format = new SimpleDateFormat(pattern)
       return format.format(new Date())
}
kazurayam@N01-0370 MINGW64 ~/tmp
$ groovy 15451.groovy
14-Dec-2018 09:48:51

This worked fine. This proves your script is just legal, has no problem as a Groovy script.

I made a Test Case in a new Katalon Studio project, copied & pasted your script into it, ran it, and got a error:

12-14-2018 09:25:47 AM Test Cases/TC1

Elapsed time: 0.435s

Test Cases/TC1 FAILED.
Reason:
BUG! exception in phase 'semantic analysis' in source unit 'file:/C:/Users/qcq0264/katalon-workspace/KatalonForum15451/Scripts/TC1/Script1544747107739.groovy' ClassNode#getTypeClass for Script1544747107739 is called before the type class is set 
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:252)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:181)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:292)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:185)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:274)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:183)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:101)
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:71)
	at com.kms.katalon.core.ast.AstTestStepTransformation.getKeywordNameForStatement(AstTestStepTransformation.groovy:306)
	at com.kms.katalon.core.ast.AstTestStepTransformation.visit(AstTestStepTransformation.groovy:254)
	at com.kms.katalon.core.ast.AstTestStepTransformation.visit(AstTestStepTransformation.groovy:78)
	at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:321)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1544747144293.run(TempTestCase1544747144293.groovy:22)

Among the lines I got interested in the line:

ClassNode#getTypeClass for Script1544747107739 is called before the type class is set 
	at com.kms.katalon.core.ast.AstTextValueUtil.getTextValue(AstTextValueUtil.java:252)

This line firmly tells you that the method getTextValue of the class com.kms.katalon.core.ast.AstTextValueUtil is calling the getTypeClass method of the org.codehaus.groovy.ast.ClassNode class.

You can read the api document here:

The document tells you as follows:

public Class getTypeClass()
Returns the concrete class this classnode relates to. However, this method is inherently unsafe as it may return null depending on the compile phase you are using. AST transformations should never use this method directly, but rather obtain a new class node using getPlainNodeReference() .
Returns:
the class this classnode relates to. May return null.

this method is inherently unsafe as it may return null depending on the compile phase you are using” : I think this is the reason why we got “BUG! exception in phase ‘semantic analysis’ in source unit” message.

I want to point out that the document sais: “AST transformations should never use this method directly”. However, the StackTrace above clearly indicates that com.kms.katalon.core.ast.AstTextValueUtil.getTextValue is directly using the getTypeClass method. Katalon should not do this. I think this should be regarded as a bug.

By the way, ‘AST’ means “Abstract Syntax Tree”. See http://glaforge.appspot.com/article/groovy-ast-transformations-tutorials for Groovy’s internal magic.


#3

:smiley: Thank KAZ for your in depth / detailed reply.

Katalon Team … Indeed You are doing a great Job. Keep up the good work. I believe this issue is worth fixing in 5.10 release … :wink:


#4

#5

#6

Thank you @kazurayam @discover.selenium. I’ve reopened the topic for the team to investigate. Just to clarify, was removing static make things work properly for you?


Multiple Test Cases in a Test Suite can share a Excel file to read/write data dynamically
#7

Yes devalex : removing static solved the problem.


#8

This is still an issue in Katalon 5.10.1


#9

I am still struggling with this issue. Please fix this bug Katalon Team. It’s a major wall for me and my team at work.


#10

Thanks for pointing out to remove static, this helped me get my code working again. Hopefully the Katalon team addresses this issue soon in a future update.