Skip to content

Fix leaking in ImmutableList#fromArray - #3968

Open
wadoon wants to merge 3 commits into
mainfrom
weigl/ilist2
Open

Fix leaking in ImmutableList#fromArray#3968
wadoon wants to merge 3 commits into
mainfrom
weigl/ilist2

Conversation

@wadoon

@wadoon wadoon commented Aug 16, 2026

Copy link
Copy Markdown
Member

Related Issue

This pull request closes #3967.

Intended Change

Type of pull request

  • Bug fix (non-breaking change which fixes an issue)

Ensuring quality

  • I made sure that introduced/changed code is well documented (javadoc and inline comments).
  • I added new test case(s) for new functionality.
  • I have tested the feature as follows: test cases

@wadoon wadoon changed the title fix leaking Fix leaking in ImmutableList#fromArray Aug 16, 2026
@wadoon wadoon self-assigned this Aug 16, 2026
@wadoon
wadoon requested a review from mattulbrich August 16, 2026 13:36
default ImmutableList<T> prepend(T... array) {
return new ImmutableListConcat<>(ImmutableList.fromArray(array), this);
// weigl: here we can use the leaky version
return new ImmutableListConcat<>(new ImmutableListArray<>(array), this);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we use this here. See the added test cases ...

/// @param array the array to wrap
/// @return an ImmutableList containing the elements of the input array
static <T extends @Nullable Object> ImmutableList<T> fromArray(T[] array) {
return new ImmutableListArray<>(Arrays.copyOf(array, array.length));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to use array.clone().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to make the checker framework happy)

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

Successfully merging this pull request may close these issues.

Immutable lists are mutable

2 participants