Francisco Francisco - 1 year ago 123
Groovy Question

Script Runner Error 'Failed type checking'

I am trying to use script runner to be able to check my scripts for any error/deprecated classes. However for a few files simply said the following error:

Failed type checking and we don't know why, it's our fault not yours @ line 1, column 1.

I've isolated the problem to the following:

Map tmprc = issue.getCustomFieldValue(rcObj) as Map
if (tmprc) {
// Root Cause Category field defined but ensure both parts of its cascading field are selected
rotCausEntered = ((tmprc.get(null) != null) && (tmprc.get("1") != null))

In particular is is the following bit of code causing the error

(tmprc.get(null) != null)

Just curious if anyone knows why this bit of code is causing the error. If I comment the line out everything works fine.

Answer Source

It makes sense that this would fail in a type-checking scenario, since null is not a type and you're passing it to a function get() that expects an Object type parameter. For example, if you run null instanceof Object, it returns false. The type-checker probably doesn't know how to handle that and is returning the error you're seeing.

Why you are using null as a key in a Map? Changing that behavior is probably your solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download