]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged test case and fix for #2796: Throw an error if the same debugId is used for...
authorArtur Signell <artur.signell@itmill.com>
Tue, 24 Mar 2009 08:07:50 +0000 (08:07 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 24 Mar 2009 08:07:50 +0000 (08:07 +0000)
http://dev.itmill.com/ticket/2796

svn changeset:7139/svn branch:6.0

src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
src/com/itmill/toolkit/tests/components/MultipleDebugIds.java [new file with mode: 0644]

index 7510c401ef94605a4e63637c463ffeac4e168b9c..16281a3c8a3586cedabcedde3cf98310d709ffc2 100644 (file)
@@ -1110,8 +1110,25 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
             } else {
                 id = "PID_S" + id;
             }
+            Paintable old = idPaintableMap.put(id, paintable);
+            if (old != null && old != paintable) {
+                /*
+                 * Two paintables have the same id. We still make sure the old
+                 * one is a component which is still attached to the
+                 * application. This is just a precaution and should not be
+                 * absolutely necessary.
+                 */
+
+                if (old instanceof Component
+                        && ((Component) old).getApplication() != null) {
+                    throw new IllegalStateException("Two paintables ("
+                            + paintable.getClass().getSimpleName() + ","
+                            + old.getClass().getSimpleName()
+                            + ") have been assigned the same id: "
+                            + paintable.getDebugId());
+                }
+            }
             paintableIdMap.put(paintable, id);
-            idPaintableMap.put(id, paintable);
         }
 
         return id;
diff --git a/src/com/itmill/toolkit/tests/components/MultipleDebugIds.java b/src/com/itmill/toolkit/tests/components/MultipleDebugIds.java
new file mode 100644 (file)
index 0000000..db5ba15
--- /dev/null
@@ -0,0 +1,35 @@
+package com.itmill.toolkit.tests.components;
+
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.TextField;
+
+public class MultipleDebugIds extends TestBase {
+
+    @Override
+    protected String getDescription() {
+        return "An exception should be thrown if the same debugId is assigned to several components";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 2796;
+    }
+
+    @Override
+    protected void setup() {
+        TextField textField = new TextField();
+        TextField textField2 = new TextField();
+        Button button = new Button();
+        Button button2 = new Button();
+        textField.setDebugId("textfield");
+        button.setDebugId("button");
+        textField2.setDebugId("textfield2");
+        button2.setDebugId("textfield");
+
+        addComponent(textField);
+        addComponent(textField2);
+        addComponent(button);
+        addComponent(button2);
+    }
+
+}