RexxLA / NetRexx

Other
6 stars 0 forks source link

Concatenating null values #34

Open rvjansen opened 1 year ago

rvjansen commented 1 year ago

While testing a planned refresh release of BSF4ooRexx I have been going through the NetRexx samples (NetRexx invoking ooRexx scripts and accessing e.g. an ooRexx directory object and the like) and stumbled over the following problem:

===== Exception running class nrxRunRexx_05: java.lang.NullPointerException: Right operand null ===== --- in nrxRunRexx_05.main(String[]) [nrxRunRexx_05.nrx:2] 38 +++ say " (NetRexx) rexxDotHost.sendMessage0(\"rexx.hey\"): [" || rexxDotHost.sendMessage0("rexx.hey")"]" +++ ^ Indeed the result of sending the ooRexx message "rexx.hey" to the RexxProxy referred to by rexxDotHost returns null (this is on purpose in this particular example).

However, concatenating strings with null has been possible in the past (have not tested the NetRexx samples in a long time). It should not throw an exception as a String value of null is perfectly valid in Java (will use 'null' as a string replacement in such cases). I do not remember whether NetRexx would have used 'null' or an empty string '' in the past to represent null values.

---rony

P.S.: The NetRexx samples in BSF4ooRexx match 1:1 the Java samples, so it is more than awkward if a NetRexx program raises an exception where the matching Java program runs through successfully.

rvjansen commented 1 year ago

On 08.08.2022 16:35, rvjansen@xs4all.nl wrote: Afaik the say function protects against nulls; concatenation does not. The samples used to work in the past, not sure when this change got incorporated.

ooRexx when carrying out a string related operation and one of the arguments is not a string it will ask the object for its string representation and use it. As the null value is a proper ooRexx singleton object (referrable via the environment symbol .nil) it will return its string rendering as "The NIL object".

NetRexx does actually the same: whenever non-String objects are used, e.g. in a concatenation, their string values (toString()) get used instead. The following NetRexx program:

say "Object():" Object() say "Object() || Object():" Object() || Object() yields

Program test.nrx ===== Exec: test ===== Object(): java.lang.Object@1e80bfe8 Object() || Object(): java.lang.Object@66a29884java.lang.Object@4769b07b Processing of 'test.nrx' complete The only difference to this use case is, that one of the references has no value, is null. In Java the string (in lowercase) 'null' is used instead, but there will be never an exception thrown!

As concatenation is a string-related function it should not throw an exception. Probably it should use the Java notion for a string null, namely: null (in lowercase). [One could argue that in Rexx no value is represented as a null string, an empty string, hence one should use a null string for null values, but then one will lose the information that one of the participants was null as one cannot see a null string/empty string.

---rony