Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
5 years ago

Assertion using groovy sometimes throws java.lang,NullPointerException

Hi,

when i try to assert a group assertion like:

assert slurperresponse.values.data.name.person== true
assert slurperresponse.values.data.address.person== true
assert slurperresponse.values.data.car.person== true
assert slurperresponse.values.data.city.person== true
assert slurperresponse.values.data.country.person== true
assert slurperresponse.values.data.province.person== true
assert slurperresponse.values.data.code.person== true
assert slurperresponse.values.data.group.person== true

It works for sometime.

After sometime it throws java.lang.NullPointerException saying java.lang.NullPointerException:Cannot get person on null object.

If i remove the last assertion it works again.

i tried this:

if(slurperresponse.values.data.group.person != null){

assert slurperresponse.values.data.group.person== true

}

i got the same error.

If i wait for sometime then it works.

 

Is there a probleme with memory leak or garbage collection .

Did someone notice this behavior ?

Or is there a better way to reduce all lines?

Thank you

 

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Difficult to say.
    Try couple of times and see.

    One question is the value boolean? or some name?
    • _ivanovich_'s avatar
      _ivanovich_
      Frequent Contributor

      Yes i tried couple of time and the result is same:

      it works sometime then it fails at this moment the variable is null.

      cannot figure out how it's possible.

      The value is a name because it retrieve from json response as string and store it in project level properties.

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        Are you running the assertion without running the step?