Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4254

ImmutableBeans should make an immutable copy of property values of type List, Set, or Map

Rank to TopRank to BottomBulk Copy AttachmentsBulk Move AttachmentsVotersWatch issueWatchersConvert to sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.26.0
    • None
    • None

    Description

      ImmutableBeans should make an immutable copy of values of type List, Set or Map when they are provided via a setter method. For example, this is how it should work:

      MyBean bean = ImmutableBeans.create(MyBean.class);
      List<Integer> evens = Arrays.asList(2, 4, 6);
      bean = bean.withNumbers(evens);
      assertThat(bean.getNumbers(), equalTo(evens));
      assertThat(bean.getNumbers(), isInstanceOf(ImmutableList.class));
      

      Note that evens has been converted to an ImmutableList with the same contents.

      You can control this behavior by setting makeImmutable = false when you declare the property:

      interface MyBean {
        @ImmutableBean.Property(makeImmutable = false)
        List<Integer> getNumbers();
      
        MyBean withNumbers(List<Integer> numbers);
      }
      

      By default, makeImmutable is true. This will change behavior of a very few existing beans that were assuming that the value that was put in would be the value that came out (see a couple of changes in VolcanoPlannerTest), but for the vast majority, immutability is the desired behavior.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            julianhyde Julian Hyde
            julianhyde Julian Hyde
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment