esa / CCSDS_MO_APIS

Holds the generated Java APIs for the CCSDS MO services
Other
2 stars 6 forks source link

String based structures initialied with null #17

Open yannickl96 opened 5 years ago

yannickl96 commented 5 years ago

While implementing regression tests for the Nanosat MO Framework I found out that objects of the types URI and Identifier are initialized with the values null when created with their default constructor. Furthermore, the constructor URI/Identifier(String) checks if the provided String is a null reference, but only logs the incident and does not initialize the underlying value in any way. Therefore, objects created with the default constructor or initialized with a null String cause a NullPointerException when you try to call the method hashCode (which happens for example when you want to use an Identifier as the key of a HashMap).

In the branch 'fix_structures' I provided a possible fix which makes the code a little bit more robust, by initializing the values of Identifier and URI with empty String objects, if nothing/null is provided to the constructor. I will open a pull request, so you can review the changes and apply the patches to the code.

CesarCoelho commented 3 years ago

I checked the code and now if start it with a null, the code will convert that into an empty String: ""

Is this the right behavior that we want? Maybe it would be better to throw an exception entirely, no?