From 1bd51f4b0fd924bc70f8b66501c8c19f1a4a2a16 Mon Sep 17 00:00:00 2001 From: mindless Date: Sat, 6 Feb 2010 01:33:01 +0000 Subject: [PATCH] [FIXED HUDSON-5469] avoid NPE and show better error message if view type is missing when creating a view (can be done by submitting form with enter key.. the OK button is disabled) git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@27057 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/View.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 2472556fa3..6dade458c1 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -205,17 +205,17 @@ public abstract class View extends AbstractModelObject implements AccessControll * If true, only show relevant executors */ public boolean isFilterExecutors() { - return filterExecutors; - } + return filterExecutors; + } /** * If true, only show relevant queue items */ public boolean isFilterQueue() { - return filterQueue; + return filterQueue; } - /** + /** * Gets the {@link Widget}s registered on this object. * *

@@ -671,7 +671,8 @@ public abstract class View extends AbstractModelObject implements AccessControll return Item.CREATE; } - public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner) throws ParseException, FormException, IOException, ServletException { + public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner) + throws ParseException, FormException, IOException, ServletException { req.setCharacterEncoding("UTF-8"); String name = req.getParameter("name"); @@ -679,8 +680,12 @@ public abstract class View extends AbstractModelObject implements AccessControll if(owner.getView(name)!=null) throw new FormException(Messages.Hudson_ViewAlreadyExists(name),"name"); + String mode = req.getParameter("mode"); + if (mode==null || mode.length()==0) + throw new FormException(Messages.View_MissingMode(),"mode"); + // create a view - View v = all().findByName(req.getParameter("mode")).newInstance(req,req.getSubmittedForm()); + View v = all().findByName(mode).newInstance(req,req.getSubmittedForm()); v.owner = owner; // redirect to the config screen