Skip to content

Immutable lists are mutable #3967

Description

@mattulbrich

Description

The immutable data structures are strictly immutable by design.

However currently, they allow indirect modification after initialisation.

Reproducible

always

Steps to reproduce

Add the following test cases to class ImmutableListArrayTest

    @Test
    void immutability1() {
        Integer[] array = { 0, 1, 4};
        ImmutableListArray<Integer> list = new ImmutableListArray<>(array);
        array[2] = 2;
        assertThat(list.get(2)).isEqualTo(4);
    }

    @Test
    void immutability2() {
        Integer[] array = { 0, 1, 4};
        ImmutableList<Integer> list = ImmutableList.fromArray(array);
        array[2] = 2;
        assertThat(list.get(2)).isEqualTo(4);
    }

They fail. In both cases the value list.get(2) is 2.

Additional information


Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions