Skip to content

FlatFileItemReaderBuilder.addComment() throws UnsupportedOperationException after comments(...) #5520

Closed

Description

@hunseonglee

Bug description
FlatFileItemReaderBuilder.comments(String...) stores the fixed-size list returned by Arrays.asList:

public FlatFileItemReaderBuilder<T> comments(String... comments) {
    this.comments = Arrays.asList(comments);
    return this;
}

A subsequent addComment(String) calls List.add on that list and throws UnsupportedOperationException, although both methods are documented to compose ("Add a string to the list of Strings that indicate commented lines").

Environment
Spring Batch main at cb69762 (6.0.x), also present in 5.x. JDK 21.

Steps to reproduce

new FlatFileItemReaderBuilder<Foo>().name("fooReader")
    .resource(resource)
    .comments("@")
    .addComment("+")   // UnsupportedOperationException at AbstractList.add
    ...

Expected behavior
comments(...) stores a mutable list (matching how the field default is initialized), so addComment(...) can be used afterwards. I will submit a PR with a fix and a test.

Activity

  1. added a commit that references this issue on Sep 16, 2026
    f7e73a7
  2. added this to the 6.1.0-RC1 milestone on Sep 30, 2026
  3. added a commit that references this issue on Sep 30, 2026
    c43c276
  4. added a commit that references this issue on Sep 30, 2026
    523eeda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions