From 4576118c0d64d02d41a1d57f2587c715ef146d9b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 11:33:56 +0000 Subject: [PATCH 1/3] Initial plan From 03207545d71a9561e4622f864ba789717d6a7679 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 11:41:03 +0000 Subject: [PATCH 2/3] Fix HasComponents to accept Collection - Updated add(Collection) signature to accept Collection - Updated remove(Collection) signature to accept Collection - Added tests in HasComponentsTest for typed collections - Added tests in DivTest for real-world usage with Span components Co-authored-by: mshabarov <61410877+mshabarov@users.noreply.github.com> --- .../vaadin/flow/component/html/DivTest.java | 33 +++++++++++++++ .../vaadin/flow/component/HasComponents.java | 4 +- .../flow/component/HasComponentsTest.java | 40 +++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java b/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java index 57bf5f06d62..b7d164bd89c 100644 --- a/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java +++ b/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java @@ -50,4 +50,37 @@ protected void testHasAriaLabelIsNotImplemented() { void testNonDefaultConstructor() { assertEquals("text", new Div("text").getText()); } + + @Test + public void testAddTypedCollectionOfComponents() { + // Test for the GitHub issue fix - should compile and work with typed collections + Div container = new Div(); + + // Create a List (subtype of Component) + java.util.List typedSpans = java.util.List + .of(new Span("span1"), new Span("span2"), new Span("span3")); + + // This should now compile with Collection + container.add(typedSpans); + + assertEquals(3, container.getChildren().count()); + } + + @Test + public void testRemoveTypedCollectionOfComponents() { + Div container = new Div(); + + Span span1 = new Span("span1"); + Span span2 = new Span("span2"); + Span span3 = new Span("span3"); + + container.add(span1, span2, span3); + assertEquals(3, container.getChildren().count()); + + java.util.List typedSpans = java.util.List.of(span1, span2); + + container.remove(typedSpans); + + assertEquals(1, container.getChildren().count()); + } } diff --git a/flow-server/src/main/java/com/vaadin/flow/component/HasComponents.java b/flow-server/src/main/java/com/vaadin/flow/component/HasComponents.java index ff2b93d77c4..31642d1c855 100644 --- a/flow-server/src/main/java/com/vaadin/flow/component/HasComponents.java +++ b/flow-server/src/main/java/com/vaadin/flow/component/HasComponents.java @@ -76,7 +76,7 @@ default void add(Component... components) { * @param components * the components to add */ - default void add(Collection components) { + default void add(Collection components) { Objects.requireNonNull(components, "Components should not be null"); throwIfTextBindingIsActive("add"); if (hasChildrenBinding()) { @@ -145,7 +145,7 @@ default void remove(Component... components) { * if there is a component whose non {@code null} parent is not * this component */ - default void remove(Collection components) { + default void remove(Collection components) { Objects.requireNonNull(components, "Components should not be null"); throwIfTextBindingIsActive("remove"); if (hasChildrenBinding()) { diff --git a/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java b/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java index 15ed2c305b8..2c1242ffeee 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java @@ -432,6 +432,46 @@ public void textBindingActive_bindChildrenThrows() { "bindChildren should throw while text binding is active"); } + @Test + public void addTypedCollection_allowsAddingListOfSubtypes() { + TestComponent container = new TestComponent(); + + java.util.List typedComponents = java.util.List + .of(new TestComponent("comp1"), new TestComponent("comp2"), + new TestComponent("comp3")); + + container.add(typedComponents); + + assertEquals(3, container.getChildren().count()); + assertEquals("comp1", + container.getChildren().toList().get(0).getId().orElse(null)); + assertEquals("comp2", + container.getChildren().toList().get(1).getId().orElse(null)); + assertEquals("comp3", + container.getChildren().toList().get(2).getId().orElse(null)); + } + + @Test + public void removeTypedCollection_allowsRemovingListOfSubtypes() { + TestComponent container = new TestComponent(); + + TestComponent comp1 = new TestComponent("comp1"); + TestComponent comp2 = new TestComponent("comp2"); + TestComponent comp3 = new TestComponent("comp3"); + + container.add(comp1, comp2, comp3); + assertEquals(3, container.getChildren().count()); + + java.util.List typedComponents = java.util.List + .of(comp1, comp2); + + container.remove(typedComponents); + + assertEquals(1, container.getChildren().count()); + assertEquals("comp3", + container.getChildren().toList().get(0).getId().orElse(null)); + } + private TestComponent createContainerWithTextBinding() { TestComponent container = new TestComponent(); TextBindingFeature feature = container.getElement().getNode() From 7daec3ad3a7e006bb93d2d37b153007f85b95e2a Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Thu, 19 Feb 2026 19:01:17 +0100 Subject: [PATCH 3/3] cleanup --- .../vaadin/flow/component/html/DivTest.java | 33 ------------------- .../flow/component/HasComponentsTest.java | 15 +++++---- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java b/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java index b7d164bd89c..57bf5f06d62 100644 --- a/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java +++ b/flow-html-components/src/test/java/com/vaadin/flow/component/html/DivTest.java @@ -50,37 +50,4 @@ protected void testHasAriaLabelIsNotImplemented() { void testNonDefaultConstructor() { assertEquals("text", new Div("text").getText()); } - - @Test - public void testAddTypedCollectionOfComponents() { - // Test for the GitHub issue fix - should compile and work with typed collections - Div container = new Div(); - - // Create a List (subtype of Component) - java.util.List typedSpans = java.util.List - .of(new Span("span1"), new Span("span2"), new Span("span3")); - - // This should now compile with Collection - container.add(typedSpans); - - assertEquals(3, container.getChildren().count()); - } - - @Test - public void testRemoveTypedCollectionOfComponents() { - Div container = new Div(); - - Span span1 = new Span("span1"); - Span span2 = new Span("span2"); - Span span3 = new Span("span3"); - - container.add(span1, span2, span3); - assertEquals(3, container.getChildren().count()); - - java.util.List typedSpans = java.util.List.of(span1, span2); - - container.remove(typedSpans); - - assertEquals(1, container.getChildren().count()); - } } diff --git a/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java b/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java index 2c1242ffeee..fb16b561ec3 100644 --- a/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/component/HasComponentsTest.java @@ -15,6 +15,8 @@ */ package com.vaadin.flow.component; +import java.util.List; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -433,12 +435,12 @@ public void textBindingActive_bindChildrenThrows() { } @Test - public void addTypedCollection_allowsAddingListOfSubtypes() { + public void add_typedCollectionOfSubtypes_addsAllChildren() { TestComponent container = new TestComponent(); - java.util.List typedComponents = java.util.List - .of(new TestComponent("comp1"), new TestComponent("comp2"), - new TestComponent("comp3")); + List typedComponents = List.of( + new TestComponent("comp1"), new TestComponent("comp2"), + new TestComponent("comp3")); container.add(typedComponents); @@ -452,7 +454,7 @@ public void addTypedCollection_allowsAddingListOfSubtypes() { } @Test - public void removeTypedCollection_allowsRemovingListOfSubtypes() { + public void remove_typedCollectionOfSubtypes_removesMatchingChildren() { TestComponent container = new TestComponent(); TestComponent comp1 = new TestComponent("comp1"); @@ -462,8 +464,7 @@ public void removeTypedCollection_allowsRemovingListOfSubtypes() { container.add(comp1, comp2, comp3); assertEquals(3, container.getChildren().count()); - java.util.List typedComponents = java.util.List - .of(comp1, comp2); + List typedComponents = List.of(comp1, comp2); container.remove(typedComponents);