JsonObject remains uninitialized
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 881
- Forks
- 285
- Avg merge
- 3d 36m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the newJson() return-parameter example on Business Central 19 and compare it with version 18, where the empty JsonObject was initialized. Trace the AL compiler or developer-tool handling of unassigned JsonObject return parameters; done means the function returns a usable empty object and jsonvar.Add('Testproperty', 42) no longer raises a runtime error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100