Skip to content

Commit 82f8f2b

Browse files
authored
fix: Array type should be serializable (#22254)
Not depending on what type array is given to Serializable... the copied array should be of type Serializable[] to enable adding Element to it.
1 parent d6ff8c9 commit 82f8f2b

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/dom/Element.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,8 @@ public PendingJavaScriptResult executeJs(String expression,
14721472
if (parameters.length == 0) {
14731473
wrappedParameters = new Serializable[] { this };
14741474
} else {
1475-
wrappedParameters = Arrays.copyOf(parameters,
1476-
parameters.length + 1);
1475+
wrappedParameters = Arrays.copyOf(parameters, parameters.length + 1,
1476+
Serializable[].class);
14771477
wrappedParameters[parameters.length] = this;
14781478
}
14791479

‎flow-server/src/test/java/com/vaadin/flow/dom/ElementTest.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.Test;
3939
import org.mockito.Mockito;
4040

41+
import com.vaadin.flow.component.Component;
4142
import com.vaadin.flow.component.Html;
4243
import com.vaadin.flow.component.Tag;
4344
import com.vaadin.flow.component.UI;
@@ -2572,6 +2573,27 @@ public PendingJavaScriptResult executeJs(String expression,
25722573
Assert.assertEquals(Boolean.TRUE, invokedParams.get()[1]);
25732574
}
25742575

2576+
@Test
2577+
public void givenTypeDefinedArray_ArrayStoreExceptionNotThrown() {
2578+
Element element = new Element("div") {
2579+
@Override
2580+
public PendingJavaScriptResult executeJs(String expression,
2581+
Serializable... parameters) {
2582+
Serializable[] wrappedParameters;
2583+
if (parameters.length == 0) {
2584+
wrappedParameters = new Serializable[] { this };
2585+
} else {
2586+
wrappedParameters = Arrays.copyOf(parameters,
2587+
parameters.length + 1, Serializable[].class);
2588+
wrappedParameters[parameters.length] = this;
2589+
}
2590+
return null;
2591+
}
2592+
};
2593+
2594+
element.executeJs("foo", new Component[] { new Div() });
2595+
}
2596+
25752597
@Test
25762598
public void callFunction_delegatesToCallJsFunction() {
25772599
AtomicReference<String> invokedFuction = new AtomicReference<>();
@@ -2632,4 +2654,8 @@ private static ArrayNode createNumberArray(double... items) {
26322654
.collect(JacksonUtils.asArray());
26332655
}
26342656

2657+
@Tag("div")
2658+
private static class Div extends Component {
2659+
}
2660+
26352661
}

0 commit comments

Comments
 (0)