NotesJsonNavigator.getNthElement does not obey boundries

I stumbled upon an issue with NotesJsonNavigator getNthElement(index) method.

It looks like there is no boundry check, which leads to some inconsitent behaviour and unpredictable results.

Here is the code that I used in my test.

%REM
	Sub testJsonNavGetNthElement
%END REM
Public Sub testJsonNavGetNthElement
	Dim s As New NotesSession 
	Dim jsnav As NotesJSONNavigator
	Dim el As NotesJSONElement
	
	Set jsnav = s.CreateJSONNavigator(|{ "element1" : "value 1", "element2" : "value 2", "element3 ": "value 3" }|)	
	
	Set el = jsnav.GetNthElement(0)
	Stop
	Set el = jsnav.GetNthElement(1)
	Stop
	Set el = jsnav.GetNthElement(2)
	Stop
	Set el = jsnav.GetNthElement(3)
	Stop
	Set el = jsnav.GetNthElement(1000)
	Stop
End Sub

The issue occurs with index < 1 and > upper bound of the array.

Index 0 AND index 1 both return the same value; “value 1“.
Index 1000 returns NULL or nothing.

This is not the expected behaviour. At least I would expect some “out of bounds” error.
Also, it is not clear for me what the base for the index is. Do we start counting at 0 or do we start with 1 ?

According to the documentation, the index is 1-based.

One thought on “NotesJsonNavigator.getNthElement does not obey boundries

  1. While I think Index 0 should be an error, I am not entirely sure that index 1000 as null is incorrect behavior. Given how JSON uses an indeterminate-length array, it makes some sense to say that anything beyond the length is just an empty slot waiting to be filled. Then, if I have two arrays and am comparing them, the fact that one has 5 items and another has 7 shouldn’t stop me from doing so. The last two items will never match, of course. Raising an error at that point would be harder to deal with than just allowing an “empty slot” beyond the defined slots.

    Of course, this should be well described in the documentation.

Comments are closed.