Skip to content

[core] Copy the branch list before adding the main branch in orphan clean - #10216

Open
LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:m/core-034-orphan-branches-mutation
Open

LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:m/core-034-orphan-branches-mutation

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Purpose

OrphanFilesClean.validBranches took the list returned by the branch manager and appended the main branch to it in place. For a table without branches the REST branch manager returns an immutable empty list, since RESTApi.listBranches falls back to Collections.emptyList(), so the add threw UnsupportedOperationException and aborted orphan file cleaning. A cached or otherwise shared list would be corrupted the same way. This copies the branch list into a new ArrayList before adding the main branch.

Tests

Added OrphanFilesCleanTest.testValidBranchesDoesNotMutateManagerList. It mocks the branch manager to return Collections.emptyList() and asserts validBranches returns exactly [main]. Without the fix this test errors with UnsupportedOperationException.

API and Format

No.

Documentation

No.

…lean

OrphanFilesClean.validBranches used the branch manager's returned list
directly and appended the main branch to it. The REST branch manager
serves Collections.emptyList() for a table without branches, so the
add threw UnsupportedOperationException and aborted the orphan-files
cleaning; a cached or otherwise shared list would be poisoned the same
way.

Copy the list before mutating it.

Assisted-by: GLM-5.3
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.

1 participant