Skip to content

Commit

Permalink
[FIXED JENKINS-15309] Be robust against serialized ListView with jobN…
Browse files Browse the repository at this point in the history
…ames==null.
  • Loading branch information
jglick committed Apr 30, 2013
1 parent 0c4fe2d commit fd31a5d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class=bug>
Display Name is not shown.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17715">issue 17715</a>)
<li class=bug>
List views missing a required field were unloadable.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15309">issue 15309</a>)
<li class='major bug'>
Properly find parent POMs when fingerprinting a Maven project.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17775">issue 17775</a>)
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/model/ListView.java
Expand Up @@ -66,7 +66,7 @@ public class ListView extends View implements Saveable {
* List of job names. This is what gets serialized.
*/
@GuardedBy("this")
/*package*/ final SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
/*package*/ /*almost-final*/ SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);

private DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>> jobFilters;

Expand Down Expand Up @@ -108,6 +108,9 @@ public ListView(String name, ViewGroup owner) {
private Object readResolve() {
if(includeRegex!=null)
includePattern = Pattern.compile(includeRegex);
if (jobNames == null) {
jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
}
initColumns();
initJobFilters();
return this;
Expand Down
44 changes: 44 additions & 0 deletions test/src/test/java/hudson/model/ListViewTest.java
@@ -0,0 +1,44 @@
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

public class ListViewTest {

@Rule public JenkinsRule j = new JenkinsRule();

@Bug(15309)
@LocalData
@Test public void nullJobNames() throws Exception {
assertTrue(j.jenkins.getView("v").getItems().isEmpty());
}

}
@@ -0,0 +1,50 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.0</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/>
<securityRealm class="hudson.security.SecurityRealm$None"/>
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
<workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir>
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
<jdks/>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
<clouds/>
<slaves/>
<scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<views>
<hudson.model.AllView>
<owner class="hudson" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
<listView>
<owner class="hudson" reference="../../.."/>
<name>v</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
<jobFilters/>
<columns>
<hudson.views.StatusColumn/>
<hudson.views.WeatherColumn/>
<hudson.views.JobColumn/>
<hudson.views.LastSuccessColumn/>
<hudson.views.LastFailureColumn/>
<hudson.views.LastDurationColumn/>
<hudson.views.BuildButtonColumn/>
</columns>
</listView>
</views>
<primaryView>All</primaryView>
<slaveAgentPort>0</slaveAgentPort>
<label></label>
<nodeProperties/>
<globalNodeProperties/>
</hudson>

0 comments on commit fd31a5d

Please sign in to comment.