Bug 414156 - NullPointerException if text is disposed during Modify
event
Change-Id: Ic8c214123acf65617c0c3c28d1b2812cf8872392
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index 980eb3d..ba8e9dc 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -415,7 +415,12 @@
}
void applySegments () {
- if (!hooks (SWT.Segments) && !filters (SWT.Segments)) return;
+ /*
+ * It is possible (but unlikely), that application code could have
+ * disposed the widget in the modify event. If this happens, return to
+ * cancel the operation.
+ */
+ if (isDisposed() || (!hooks (SWT.Segments) && !filters (SWT.Segments))) return;
Event event = new Event ();
String string = getText ();
event.text = string;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
index 5d1ce85..fba9850 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -459,7 +459,12 @@
}
void applySegments () {
- if (--clearSegmentsCount != 0) return;
+ /*
+ * It is possible (but unlikely), that application code could have
+ * disposed the widget in the modify event. If this happens, return to
+ * cancel the operation.
+ */
+ if (isDisposed() || --clearSegmentsCount != 0) return;
if (!hooks (SWT.Segments) && !filters (SWT.Segments)) return;
int length = OS.GetWindowTextLength (handle);
int cp = getCodePage ();