Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonNullCollections flag isn't being respected for alias types #1095

Open
a-k-g opened this issue Sep 25, 2020 · 2 comments
Open

nonNullCollections flag isn't being respected for alias types #1095

a-k-g opened this issue Sep 25, 2020 · 2 comments

Comments

@a-k-g
Copy link

a-k-g commented Sep 25, 2020

What happened?

We have the following conjure type:

  AndSearchFilter:
    docs: |
      A SearchFilter used to combine multiple SearchFilters.
      A row satisfies this SearchFilter if and only if it satisfies all combined SearchFilters.
    alias: set<SearchFilter>

And we have enabled the nonNullCollections flag to enforce that the set cannot contain null entries. However, this is not being enforced.

What did you want to happen?

Constructing the AndSearchFilter with a set containing null should fail.

@mpritham
Copy link
Contributor

mpritham commented Jan 24, 2025

When the nonNullCollections flag is set, we could update the constructor to create a copy of the list passed in (for lists, via a call to this method in ConjureCollections).

The generation of this code should be under a new flag (maybe --copyCollectionsOnConstruction or something): it's currently possible that the aliased collection is mutated in some code that uses Conjure. Specifically, something like this could exist:

ListAlias createListAlias() {
  List<String> arr = new ArrayList<>();
  ListAlias listAlias = ListAlias.of(arr);
  callThatPopulatesList(arr);
  return listAlias;
}

We don't want any new changes we introduce to conjure-java to automatically lead to failures for clients that have the above (discouraged) pattern.

Conjure objects are meant to be immutable. As part of this change, when the copyCollectionsOnConstruction flag is set and the nonNullCollections flag is not set, we could create copies of collections (that allow null values) in the constructors for aliased collection types.

@carterkozak
Copy link
Contributor

bikeshed: The feature flag should be a bit more specific since we do already copy collections in most cases (conjure bean types, just not aliases!). Perhaps something along the lines of --defensiveCollectionAliases.

There are only two hard things in Computer Science: cache invalidation and naming things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants