Skip to content

Commit 3a902eb

Browse files
authored
Fix for container regression and added test coverage for that
Regression discussed here: https://www.reddit.com/r/cn1/comments/1ohgzpl/error_with_radchatroom/
1 parent c028418 commit 3a902eb

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

CodenameOne/src/com/codename1/ui/Container.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,8 +4299,6 @@ public MorphAnimation(Container thisContainer, int duration, Motion[][] motions)
42994299
}
43004300
this.thisContainer = thisContainer;
43014301
this.motions = motions;
4302-
animatedComponents = new Vector();
4303-
opacity = new Motion[0];
43044302
}
43054303

43064304
@Override
@@ -4331,7 +4329,7 @@ protected void updateState() {
43314329
currentCmp.setY(motions[1][iter].getValue());
43324330
currentCmp.setWidth(motions[2][iter].getValue());
43334331
currentCmp.setHeight(motions[3][iter].getValue());
4334-
if (opacity != null) {
4332+
if (opacity != null && iter < opacity.length) {
43354333
currentCmp.getStyle().setOpacity(opacity[iter].getValue(), false);
43364334
}
43374335
}
@@ -4351,7 +4349,7 @@ protected void updateState() {
43514349
currentCmp.setY(motions[1][iter].getValue());
43524350
currentCmp.setWidth(motions[2][iter].getValue());
43534351
currentCmp.setHeight(motions[3][iter].getValue());
4354-
if (opacity != null) {
4352+
if (opacity != null && iter < opacity.length) {
43554353
currentCmp.getStyle().setOpacity(opacity[iter].getValue(), false);
43564354
}
43574355
}

maven/core-unittests/src/test/java/com/codename1/ui/ContainerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ void testMorphAnimation() {
3030
assertEquals(c.getBounds(), a.getBounds());
3131
}
3232

33+
@FormTest
34+
void testAnimateHierarchyWithDefaultOpacityDoesNotCrash() {
35+
Form form = CN.getCurrentForm();
36+
form.removeAll();
37+
form.setLayout(BoxLayout.y());
38+
39+
Label first = new Label("First");
40+
Label second = new Label("Second");
41+
form.addAll(first, second);
42+
form.revalidate();
43+
44+
// Regression guard for commit 4e5cbc2c2092721c8861a34d557fe56fe742e82b where
45+
// MorphAnimation's constructor began initializing opacity to an empty array.
46+
// When animateHierarchy() is invoked without fade (the default, matching
47+
// Form.animateHierarchy and Codename One 7.0.208), MorphAnimation.opacity
48+
// remains zero-length yet non-null. The flush() call below mirrors Display.flushEdt()
49+
// from the stack trace and would previously trigger an ArrayIndexOutOfBoundsException.
50+
assertDoesNotThrow(() -> {
51+
form.animateHierarchy(100);
52+
form.getAnimationManager().flush();
53+
});
54+
}
55+
3356
@Test
3457
void testScrollableFlagsRespectBorderLayout() {
3558
Container container = new Container(new BorderLayout());

0 commit comments

Comments
 (0)