]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't allow null view providers (#17028)
authorLeif Åstrand <leif@vaadin.com>
Sun, 15 Mar 2015 13:09:32 +0000 (15:09 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 8 Jun 2015 08:32:16 +0000 (08:32 +0000)
Change-Id: I5ce4885f19aaac2d4454b5a368f3e58453cf76f9

server/src/com/vaadin/navigator/Navigator.java
server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java

index 65b3fec48840d90b9e3f942272ca88ef5e448fe6..bd2b5711f8816581d98ca4b4c8f2aafe4ade21b5 100644 (file)
@@ -745,9 +745,15 @@ public class Navigator implements Serializable {
      * the requested view name is found.
      * 
      * @param provider
-     *            provider to register
+     *            provider to register, not <code>null</code>
+     * @throws IllegalArgumentException
+     *             if the provided view provider is <code>null</code>
      */
     public void addProvider(ViewProvider provider) {
+        if (provider == null) {
+            throw new IllegalArgumentException(
+                    "Cannot add a null view provider");
+        }
         providers.add(provider);
     }
 
index ff6028648e4e42c7dca77f0121248dd5c5dc2e76..2c045d53fa1985fe266e45e9c470dd1ed61d215d 100644 (file)
@@ -712,4 +712,21 @@ public class NavigatorTest extends TestCase {
         navigator.addView("view", view);
         navigator.navigateTo("view");
     }
+
+    public void testNullViewProvider() {
+        IMocksControl control = EasyMock.createControl();
+        NavigationStateManager manager = control
+                .createMock(NavigationStateManager.class);
+        ViewDisplay display = control.createMock(ViewDisplay.class);
+
+        // create navigator to test
+        Navigator navigator = createNavigator(manager, display);
+
+        try {
+            navigator.addProvider(null);
+            fail("Should not be allowed to add a null view provider");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+    }
 }