Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Läubrich2020-06-12 10:30:11 -0400
committerKarsten Thoms2020-07-06 02:58:19 -0400
commit82a3f03bf35bac3c3cf3e449713cb672124f1ab1 (patch)
treeaac1ad3d0be6e1626eecf8baa712f771e1ce7ee2
parentb82d04a5dc2015f195a1fa16717a862547b62553 (diff)
downloadeclipse.platform.swt-82a3f03bf35bac3c3cf3e449713cb672124f1ab1.tar.gz
eclipse.platform.swt-82a3f03bf35bac3c3cf3e449713cb672124f1ab1.tar.xz
eclipse.platform.swt-82a3f03bf35bac3c3cf3e449713cb672124f1ab1.zip
Bug 513185 - FillLayout throws ClassCastExecption for children with
wrong layout data Change-Id: I2a1fdce982d9b3257849e5b45cb117ddd34df39e Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
index f66f280bc8..250ccc24e9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Christoph Läubrich - Bug 513185
*******************************************************************************/
package org.eclipse.swt.layout;
@@ -145,7 +146,7 @@ protected Point computeSize (Composite composite, int wHint, int hHint, boolean
}
Point computeChildSize (Control control, int wHint, int hHint, boolean flushCache) {
- FillData data = (FillData)control.getLayoutData ();
+ FillData data = validateLayoutData(control, -1);
if (data == null) {
data = new FillData ();
control.setLayoutData (data);
@@ -172,8 +173,10 @@ Point computeChildSize (Control control, int wHint, int hHint, boolean flushCach
@Override
protected boolean flushCache (Control control) {
- Object data = control.getLayoutData();
- if (data != null) ((FillData)data).flushCache();
+ FillData data = validateLayoutData(control, -1);
+ if (data != null) {
+ data.flushCache();
+ }
return true;
}
@@ -198,6 +201,7 @@ protected void layout (Composite composite, boolean flushCache) {
int y = rect.y + marginHeight, cellWidth = width / count;
for (int i=0; i<count; i++) {
Control child = children [i];
+ validateLayoutData(child, i);
int childWidth = cellWidth;
if (i == 0) {
childWidth += extra / 2;
@@ -213,6 +217,7 @@ protected void layout (Composite composite, boolean flushCache) {
int y = rect.y + marginHeight, extra = height % count;
for (int i=0; i<count; i++) {
Control child = children [i];
+ validateLayoutData(child, i);
int childHeight = cellHeight;
if (i == 0) {
childHeight += extra / 2;
@@ -225,6 +230,21 @@ protected void layout (Composite composite, boolean flushCache) {
}
}
+private FillData validateLayoutData(Control control, int index) {
+ if (control == null) {
+ throw new SWTException(SWT.ERROR_NULL_ARGUMENT, "control can't be null");
+ }
+ Object layoutData = control.getLayoutData();
+ if (layoutData == null) {
+ return null;
+ }
+ if (layoutData instanceof FillData) {
+ return (FillData) layoutData;
+ }
+ throw new SWTException(SWT.ERROR_INVALID_ARGUMENT, "Child#" + index + " of type " + control.getClass().getName()
+ + " has illegal layout data type " + layoutData.getClass().getName());
+}
+
/**
* Returns a string containing a concise, human-readable
* description of the receiver.

Back to the top