%dw 2.0
import * from dw::core::Binaries
output application/json
var userCredentials = vars.userCredentials.userName as String ++ ":" ++ vars.userCredentials.password as String
---
"Basic "++ toBase64(userCredentials as String)
Error [MULE:EXPRESSION] while running test 'get-authorization-token-test-success':"Cannot coerce Null (org.mule.weave.v2.model.values.NullValue$@799da78a) to String
1| %dw 2.0 import * from dw::core::Binaries output application/json var userCredentials = vars.userCredentials.userName as String ++ ":" ++ vars.userCredentials.password as String --- "Basic "++ toBase64(userCredentials as String)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at ++ (line: 1, column: 89)
at ++ (line: 1, column: 129)
at main (line: 1, column: 136)" evaluating expression: "%dw 2.0 import * from dw::core::Binaries output application/json var userCredentials = vars.userCredentials.userName as String ++ ":" ++ vars.userCredentials.password as String --- "Basic "++ toBase64(userCredentials as String)".

- 1
- 1
- 2
-
1What is the question? Please describe the issue, provide the values of the inputs. Kindly read https://stackoverflow.com/help/how-to-ask for tips on how to improve your question. – aled Jun 22 '21 at 11:57
2 Answers
I'll assume that the question is what is causing the error shown. The error is self describing really: You can not concatenate a null with a String. The underlined part of the script indicates the location of the issue. The problem seems to be that either the variable vars.userCredentials is null or it doesn't contain an attribute called userName. You'll have to figure why it reaches the script with a null value and fix it.

- 21,330
- 3
- 27
- 34
Double check the value stored in the vars.userCredentials
. This error comes when this value or its elements userName
or password
are null.
In your data weave, you have written the statement vars.userCredentials.userName
as String
, which in runtime gets executed as null as String ==> and hence Mule runtime engine is throwing an error.

- 7,102
- 69
- 48
- 77

- 11
- 2