disallow mutation of record types by clients#944
Conversation
588d43d to
2235582
Compare
I checked and Jakarta Data mostly covers this, but I did identify 3 places that we can fix. I will open a PR there. |
Yeah true so maybe the constructor should also clone. But I was more worried about them trying to mutate the ones returned by Anyway, good catch, I will fix it anyway. |
as suggested by @njr-11
I'm now also cloning things in record constructors. Keep finding the whole |
|
Switched the assignee back to Gavin who authored this PR. It is likely I was mistakenly added as assignee when attempting to set the reviewer. |
|
How about changing the record components to be lists instead of arrays to avoid the copying on read access? If we use |
Aaaahmm, sure, we could do that. Looks like we already used that pattern in at least one place in the Data APIs. Having a tough time deciding if it's on balance better. It's slightly better for performance, slightly worse for type safety, so I dunno 🤷♂️ |
We have some
recordtypes with array members. We should prevent mutation of the arrays by returning clones to the client.@njr-11 @otaviojava do we need to do something similar in Jakarta Data?