RESOLVED 280291: [CLabel] causes NullPointerException when rendered uninitialized
diff --git a/bundles/org.eclipse.rap.rwt.q07/src/org/eclipse/swt/internal/custom/clabelkit/CLabelLCA.java b/bundles/org.eclipse.rap.rwt.q07/src/org/eclipse/swt/internal/custom/clabelkit/CLabelLCA.java
index ee10895..ed00b1c 100644
--- a/bundles/org.eclipse.rap.rwt.q07/src/org/eclipse/swt/internal/custom/clabelkit/CLabelLCA.java
+++ b/bundles/org.eclipse.rap.rwt.q07/src/org/eclipse/swt/internal/custom/clabelkit/CLabelLCA.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2002, 2008 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2002, 2009 Innoopract Informationssysteme GmbH.
  * 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
@@ -7,8 +7,8 @@
  *
  * Contributors:
  *     Innoopract Informationssysteme GmbH - initial API and implementation
+ *     EclipseSource - ongoing development
  ******************************************************************************/
-
 package org.eclipse.swt.internal.custom.clabelkit;
 
 import java.io.IOException;
@@ -22,7 +22,7 @@
 import org.eclipse.swt.internal.widgets.Props;
 import org.eclipse.swt.widgets.Widget;
 
-public class CLabelLCA extends AbstractWidgetLCA {
+public final class CLabelLCA extends AbstractWidgetLCA {
 
   private static final String PROP_TEXT = "text";
   private static final String PROP_ALIGNMENT = "alignment";
@@ -83,17 +83,20 @@
   }
 
   private static void writeText( final CLabel label ) throws IOException {
-    if( WidgetLCAUtil.hasChanged( label, PROP_TEXT, label.getText(), "" ) ) {
+    String text = label.getText();
+    if( WidgetLCAUtil.hasChanged( label, PROP_TEXT, text, "" ) ) {
+      if( text == null ) {
+        text = "";
+      }
+      text = WidgetLCAUtil.escapeText( text, true );
       JSWriter writer = JSWriter.getWriterFor( label );
-      String text = WidgetLCAUtil.escapeText( label.getText(), true );
       writer.set( JSConst.QX_FIELD_LABEL, text );
     }
   }
 
   private static void writeImage( final CLabel label ) throws IOException {
     Image image = label.getImage();
-    if( WidgetLCAUtil.hasChanged( label, Props.IMAGE, image, null ) )
-    {
+    if( WidgetLCAUtil.hasChanged( label, Props.IMAGE, image, null ) ) {
       String imagePath;
       if( image == null ) {
         imagePath = null;
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
index 0f23a48..4ccb809 100644
--- a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/RWTQ07TestSuite.java
@@ -26,6 +26,7 @@
 import org.eclipse.swt.internal.graphics.TextSizeDeterminationHandler_Test;
 import org.eclipse.swt.internal.widgets.WidgetAdapter_Test;
 import org.eclipse.swt.internal.widgets.buttonkit.ButtonLCA_Test;
+import org.eclipse.swt.internal.widgets.clabelkit.CLabelLCA_Test;
 import org.eclipse.swt.internal.widgets.combokit.ComboLCA_Test;
 import org.eclipse.swt.internal.widgets.controlkit.ControlLCA_Test;
 import org.eclipse.swt.internal.widgets.coolbarkit.CoolBarLCA_Test;
@@ -131,6 +132,7 @@
     suite.addTestSuite( ExpandItemLCA_Test.class );
     suite.addTestSuite( SliderLCA_Test.class );
     suite.addTestSuite( CComboLCA_Test.class );
+    suite.addTestSuite( CLabelLCA_Test.class );
 
     return suite;
   }
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/clabelkit/CLabelLCA_Test.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/clabelkit/CLabelLCA_Test.java
new file mode 100644
index 0000000..3b46cff
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/clabelkit/CLabelLCA_Test.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2009 EclipseSource 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 http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   EclipseSource - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.internal.widgets.clabelkit;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.rwt.lifecycle.*;
+import org.eclipse.swt.RWTFixture;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class CLabelLCA_Test extends TestCase {
+  
+  /*
+   * 280291: [CLabel] causes NullPointerException when rendered uninitialized
+   * https://bugs.eclipse.org/bugs/show_bug.cgi?id=280291
+   */
+  public void testWriteText() throws IOException {
+    Display display = new Display();
+    Shell shell = new Shell( display );
+    CLabel label = new CLabel( shell, SWT.NONE );
+    assertNull( label.getText() ); // assert precondition: text == null
+    AbstractWidgetLCA lca = WidgetUtil.getLCA( label );
+    lca.renderChanges( label );
+    // the purpose of this test is to ensure that the LCA works without throwing 
+    // an exception - thus there is no assert
+  }
+
+  protected void setUp() throws Exception {
+    RWTFixture.setUp();
+    Fixture.fakeResponseWriter();
+  }
+
+  protected void tearDown() throws Exception {
+    RWTFixture.tearDown();
+  }
+}