diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java
index 5ab721a58f..e2c44bc773 100644
--- a/core/src/main/java/hudson/model/View.java
+++ b/core/src/main/java/hudson/model/View.java
@@ -531,7 +531,10 @@ public abstract class View extends AbstractModelObject implements AccessControll
public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner) throws ParseException, FormException, IOException, ServletException {
req.setCharacterEncoding("UTF-8");
- checkGoodName(req.getParameter("name"));
+ String name = req.getParameter("name");
+ checkGoodName(name);
+ if(owner.getView(name)!=null)
+ throw new FormException(Messages.Hudson_ViewAlreadyExists(name),"name");
// create a view
View v = LIST.findByName(req.getParameter("mode")).newInstance(req,req.getSubmittedForm());
diff --git a/test/pom.xml b/test/pom.xml
index 9e3cbf38a8..7485595a3b 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -72,7 +72,7 @@
org.jvnet.hudson
htmlunit
- 2.2-hudson-8
+ 2.2-hudson-9
diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java
new file mode 100644
index 0000000000..bc1da96904
--- /dev/null
+++ b/test/src/test/java/hudson/model/ViewTest.java
@@ -0,0 +1,33 @@
+package hudson.model;
+
+import org.jvnet.hudson.test.Email;
+import org.jvnet.hudson.test.HudsonTestCase;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class ViewTest extends HudsonTestCase {
+ /**
+ * Creating two views with the same name.
+ */
+ @Email("http://d.hatena.ne.jp/ssogabe/20090101/1230744150")
+ public void testConflictingName() throws Exception {
+ assertNull(hudson.getView("foo"));
+
+ HtmlForm form = new WebClient().goTo("newView").getFormByName("createView");
+ form.getInputByName("name").setValueAttribute("foo");
+ form.getRadioButtonsByName("mode").get(0).setChecked(true);
+ submit(form);
+ assertNotNull(hudson.getView("foo"));
+
+ // do it again and verify an error
+ try {
+ submit(form);
+ fail("shouldn't be allowed to create two views of the same name.");
+ } catch (FailingHttpStatusCodeException e) {
+ assertEquals(400,e.getStatusCode());
+ }
+ }
+}