AL icon indicating copy to clipboard operation
AL copied to clipboard

JsonObject remains uninitialized

Open LNitzsche opened this issue 4 years ago • 2 comments

1. Describe the bug A return parameter of type JsonObject will be return as uninitialized if not explicitly set.

In BC versions up to 18 you could instantiate a return parameter of any type in a procedure and the return value was valid, even if not explicitly assigned. (see code below)

2. To Reproduce

Take the function described below and check the return value. In BC 19 the return value is uninitialized.

procedure newJson() newObj: JsonObject begin end;

In versions up to BC version 18 this is a legal function, because newObj is instantiated as a local variable and contains a valid empty JSON object. This valid object will be given back to the caller. There is no need to make any assignment to jobj in the procedure body.

jsonvar := newJson() ; // will always initialize jsonvar with a new empty JsonObject jsonvar.Add('Testproperty', 42); // should work

3. Expected behavior

I would expect to have an empty JsonObject in jsonvar after the call.

4. Actual behavior

After the call jsonvar := newJson() ;
the debugger shows the content of jsonvar as "uninitialized" and jsonvar.Add('Testproperty', 42); // rises a runtime error

5. Versions:

  • AL Language: 8.1.525271
  • Visual Studio Code: 1.54.3
  • Business Central: Version: W1 19.0 (Platform 19.0.29884.30666 + Application 19.0.29894.30693)

This version and below does not have this error: Version: W1 18.0 (Platform 18.0.22893.23773 + Application 18.0.23013.23795)

Final Checklist

LNitzsche avatar Oct 15 '21 18:10 LNitzsche

The bug is still there in BC 21.4 Is there any plan to fix it?

nicolassaleron avatar Jan 12 '23 12:01 nicolassaleron

BC24 - the bug is still there :(

apoyas avatar Aug 23 '24 09:08 apoyas