Array size gets reset

Why often array size gets reset if we declare like below

array_name = new String[4]
or
size_of_array = 6
array_name = new String[size_of_array]

Often while making changes in script and saving noticed that above gets updated to
array_name = new String

Please help resolving this

Do you use the “Manual mode” of Test Case editor as well as “Script mode”?

The “Manual mode” does something curious sometimes.

Let me show you an example. You want to create a Test Case using the “Script mode”, like

array_name = new String[4]

Then you switch the editor to “Manual mode” and do something to edit the test case.

Then you may switch the editor back to “Script” mode. Then you would find the line was silently modified to something syntactically broken:

array_name = new String[]

This seems to be a bug of Test Case Editor’s “Manual mode”.

@vu.tran

will you address this as a bug?

Any workaround?

Well, perhaps, you should never switch between “Manual mode” and “Script mode”.

If you want to use “Script mode”, then you should never switch to “Manual mode”.

If you want to use “Manual mode”, then you should stick to it. Never switch to “Script mode”.

In my case, I never use the “Manual mode” as I don’t need it.

There is an effective workaround.

You shouldn’t use array of Strings, like this:

String[] array_name = new String[3]
array_name[0] = 'aaa'
array_name[1] = 'bbb'
array_name[2] = 'ccc'

In modern Java/Groovy, an array of String like new String[3] is no longer popular. Nobody uses it. Perhaps, Katalon programmers forgot that Java has the syntax of “new String[3]”. So the “Manual mode” has a defect dealing with “new String[3]”. I wouldn’t blame them. I never write “new String[3]”. Rather, you should write new ArrayList<String>() instead.

In Groovy,

//List<String> varName = ["aaa", "bbb", "ccc"]
List<String> varName = new ArrayList<>()
varName.add("aaa")
varName.add("bbb")
varName.add("ccc")
println varName[0]  // => "aaa"
println varName.get(0)  // => "aaa"
println varName[1]  // => "bbb"
println varName[2]  // => "ccc"

The statement “List<String> varName = new ArrayList<>()” is robust against this Katalon Studio’s bug.

1 Like

Thanks @kazurayam for the details and suggestions.

1 Like

Hi @kazurayam,

I already informed the support team to categorize this issue. Thanks for noticing me.

Best,