...
The underlying issue is that stage.XMLProperties
is null
, so evaluating null.Usage
triggers a NullPointerException.
NullPointerExceptions A NullPointerException
can be prevented by ensuring the code does not access null
values. There are scenarios, like the one illustrated above, where the DataStage Designer can produce a Database Connector stage with an incomplete XMLProperties
field, which the out0of-the-box MettleCI some of MettleCI’s example Compliance Rules do not handle. Later versions of MettleCI Compliance Rules will handle this situation to make it clear that the Compliance system is behaving as expected, and that the error is caused by an incomplete jobs definitionmay not handle.
There are a few tools available within Compliance Rules which make it easy to avoid this type of problem:
Change your graph traversal to ignore stages with a null
XMLProperty
. e.g.item.graph.V.stage.has('XMLProperties', T.ne, null).???
From within a
Pipe
closure (e.g.sideEffect{}
,filter{}
, etc.), you can use the Groovy safe navigation operator to cancel the evaluation and immediately return null.e.g.
stage?.XMLProperties.Usage.Session.SchemaReconciliation.FailOnTypeMismatch.toString()
would returnnull
whenXMLProperties
is null.
From within a
Pipe
closure you can use the Groovy Elvis operator to default a null value to something more usable. Usingstage.XMLProperties?:''
will return an empty string whenXMLProperties
is null. This could be combined with the Safe Navigation operator described above to produce a reasonable default string:stage?.XMLProperties.Usage.Session.SchemaReconciliation.FailOnTypeMismatch.toString()?:''
...
The example above also appends a space at the start and end of the string, and uses a .toString()
and sFOTM.substring(1,2)
to strip off the square brackets ([]
) which are present when an XML Property is an array. Given that, we’d suggest:
...