5

I try to generate load test from my testcase in SoapUI. It has a lot of test steps, from which the first 10 covers the login process. LoadTest stops in a Groovy script, which should get parameter values from the previous test step's output. It is working correctly, when it is executed directly, but gives error, when it is executed as a LoadTest:

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.String# . Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class [B] [class [C] [class java.lang.String] groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.String# . Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class [B] [class [C] [class java.lang.String] error at line: 5

Groovy script which causes error above:

def tc1 = testRunner.testCase.getTestStepAt(context.currentStepIndex-1);
String rawData = new String(tc1.testRequest.response.rawResponseData);
Reger reger = new Reger(rawData); 

String myvar1 = reger.getNthMatch(/<myregex>/, 0);
plaidshirt
  • 5,189
  • 19
  • 91
  • 181

1 Answers1

2

Your problem in this string:

String rawData = new String(tc1.testRequest.response.rawResponseData)

tc1.testRequest.response.rawResponseData is null

so to prevent exception you can change this string to:

String rawData = tc1.testRequest.response.rawResponseData?.toString()

which is null safe

Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22
  • I replaced that line, but I can't get necessary variables with this. I checked and variable `rawData` is empty if I use this line. – plaidshirt Apr 04 '18 at 06:14
  • yes because tc1.testRequest.response.rawResponseData is null. You need to check why in your code before this line – Evgeny Smirnov Apr 04 '18 at 06:47
  • Yes, but when I use this line: `String rawData = new String(tc1.testRequest.response.rawResponseData);` it is not null in case of a direct execution. In that case it is only null when I execute it on multiple threads. But code you mentioned fails on single thread too, variable is empty. – plaidshirt Apr 04 '18 at 06:52
  • Your tc1.testRequest.response.rawResponseData is null. You can check it using debugger. – Evgeny Smirnov Apr 04 '18 at 07:32
  • Yes, it is null, when executed on multiple threads, but has value, when executed on single thread, manually. When I use your code, it is null, when executed on single thread. – plaidshirt Apr 04 '18 at 07:46
  • This variable ALREADY null no matter what you will do with it new String(val) or val.toString or anything else - this will not affect to it value. Check you response data... print dump of all tc1, tc1.testRequest, tc1.testRequest.response, tc1.testRequest.response.rawResponseData at 1 line before this code... – Evgeny Smirnov Apr 04 '18 at 08:28
  • Yes, I see, but I wonder why is my current working perfectly on single thread. Value of `rawResponseData` is never null in case of manual execution. Code you posted isn't working also on single-thread. – plaidshirt Apr 05 '18 at 12:42
  • Usually in cases like this you need to deep dive into other code to check what happens. If this value shouldn't be null you need to find why it is null. – Evgeny Smirnov Apr 13 '18 at 09:51
  • toString() - is Object class method that means that any java object has is. Different objects may have different implementations of this method but finally they all return new String(someValue). ? - Groovy's safe navigation operator used to avoid null pointer exception and if can be represented as if(value != null) {return value}else{return null}. So value?.toString() in fact equals to if(value!=null){ return new String(value)}else{return null} – Evgeny Smirnov Apr 13 '18 at 09:51
  • It helpful in many cases when you need to prevent NullPointerException throw. But to check why this value is null you need to debug code. Use your IDE debugger to find in which cases it is null. – Evgeny Smirnov Apr 13 '18 at 09:51
  • Or add some println: println tc1;println tc1.testRequest;println tc1.testRequest.response;println tc1.testRequest.response.rawResponseData Check what is null and what is not null? In which cases? If you run this code in multithread environment check if there are thread unsafe code. Etc etc etc – Evgeny Smirnov Apr 13 '18 at 09:51