From 3a42436fc9ce52e9689adf7166a9c5698224ec40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Sun, 15 Mar 2015 15:09:32 +0200 Subject: [PATCH] Don't allow null view providers (#17028) Change-Id: I5ce4885f19aaac2d4454b5a368f3e58453cf76f9 --- server/src/com/vaadin/navigator/Navigator.java | 8 +++++++- .../tests/server/navigator/NavigatorTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index 65b3fec488..bd2b5711f8 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -745,9 +745,15 @@ public class Navigator implements Serializable { * the requested view name is found. * * @param provider - * provider to register + * provider to register, not null + * @throws IllegalArgumentException + * if the provided view provider is null */ public void addProvider(ViewProvider provider) { + if (provider == null) { + throw new IllegalArgumentException( + "Cannot add a null view provider"); + } providers.add(provider); } diff --git a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java index ff6028648e..2c045d53fa 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -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 + } + } } -- 2.39.5