Why does $EmptyString1 + $EmptyString2 result in an error?

0
Example: $String1 = 'FOO' $String2 = empty $String 3 = $String1 + $String2 = 'FOOnull' Why does the addition of String1 and String2 result in a "Java.lang.IllegalArgumentException: Left and right hand side of binary expression should not be empty" - error when both strings are empty? Why can't this result in a 'null', or even a 'nullnull' result?
asked
2 answers
1

I think you can not add empty  strings..

empty = no value

you can do something like replacing empty with no space or one space

"..(if $string2 = empty then ' ' else $string2)...

answered
1

This is a very good question, this is the result of a Java quirk.

The reason why this happens is that + can be used for different things, and the JVM figures out in what way it is used from the context. When one of the arguments is a String, it is assumed that + is used for String concatenation. If both arguments are Numbers (or primitives of type int, long, etc, I guess) it is assumed that it is used for addition.

If both arguments are null, they don't have a type, so there is no way to figure out what to do with the + in this case, so an error is thrown.

I agree with you that when using Mendix you shouldn't need to worry about these Java implementation details. The way this should have been handled should have been that an empty String would result. I consider it both a bug that "null" is used at all and that you run into this error in this case. I'm sure the "Existing applications rely on the current behaviour" card would be played if you submitted a change request though :).

answered