diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index e01d3085f70e58fca6fa02609f91e8cb28caac14..1852e7c11042dbe2c3f50a274badc68649cfa866 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -2868,15 +2868,12 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve // initialize views by inserting the default view if necessary // this is both for clean Jenkins and for backward compatibility. - if(views.size()==0) { + if(views.size()==0 || primaryView==null) { View v = new AllView(Messages.Hudson_ViewName()); setViewOwner(v); views.add(0,v); primaryView = v.getViewName(); } - if (primaryView==null) { - primaryView = views.get(0).getViewName(); - } if (useSecurity!=null && !useSecurity) { // forced reset to the unsecure mode. diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java index 36841da2953989136aa8839f7ae5f17830821505..82314e984118b92dc5e5d18d7549ff31067aee03 100644 --- a/test/src/test/java/hudson/model/ViewTest.java +++ b/test/src/test/java/hudson/model/ViewTest.java @@ -64,6 +64,7 @@ import org.jvnet.hudson.test.JenkinsRule.WebClient; import org.jvnet.hudson.test.MockAuthorizationStrategy; import org.jvnet.hudson.test.MockFolder; import org.jvnet.hudson.test.TestExtension; +import org.jvnet.hudson.test.recipes.LocalData; import org.kohsuke.stapler.DataBoundConstructor; /** @@ -505,5 +506,20 @@ public class ViewTest { private void assertCheckJobName(ViewGroup context, String name, FormValidation.Kind expected) { assertEquals(expected, context.getPrimaryView().doCheckJobName(name).kind); } + + + @Test + @Issue("JENKINS-36908") + @LocalData + public void testAllViewCreatedIfNoPrimary() throws Exception { + assertNotNull(j.getInstance().getView("All")); + } + + @Test + @Issue("JENKINS-36908") + @LocalData + public void testAllViewNotCreatedIfPrimary() throws Exception { + assertNull(j.getInstance().getView("All")); + } } diff --git a/test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip b/test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip new file mode 100644 index 0000000000000000000000000000000000000000..7e32a82640eaa9259f3a158b50a35a5c216737c0 Binary files /dev/null and b/test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip differ diff --git a/test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip b/test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip new file mode 100644 index 0000000000000000000000000000000000000000..397d6d14a44666ed3e5f0f52abb61fe3e055f76d Binary files /dev/null and b/test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip differ