Skip to content

Commit

Permalink
[FIXED JENKINS-9367] persistence problem in View$PropertyList
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Apr 18, 2011
1 parent eb7292e commit dfc2fe3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
Fixed a persistence problem in <tt>View$PropertyList</tt>
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9367">issue 9367</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/ListView.java
Expand Up @@ -91,7 +91,8 @@ public ListView(String name, ViewGroup owner) {
this.owner = owner;
}

private Object readResolve() {
protected Object readResolve() {
super.readResolve();
if(includeRegex!=null)
includePattern = Pattern.compile(includeRegex);
initColumns();
Expand Down
23 changes: 16 additions & 7 deletions core/src/main/java/hudson/model/View.java
Expand Up @@ -118,7 +118,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
* List of {@link ViewProperty}s configured for this view.
* @since 1.406
*/
private volatile DescribableList<ViewProperty,ViewPropertyDescriptor> properties = new PropertyList();
private volatile DescribableList<ViewProperty,ViewPropertyDescriptor> properties = new PropertyList(this);

protected View(String name) {
this.name = name;
Expand All @@ -129,9 +129,11 @@ protected View(String name, ViewGroup owner) {
this.owner = owner;
}

private Object readResolve() {
protected Object readResolve() {
if (properties == null) {
properties = new PropertyList();
properties = new PropertyList(this);
} else {
properties.setOwner(this);
}
return this;
}
Expand Down Expand Up @@ -762,15 +764,22 @@ public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup own
return v;
}

private class PropertyList extends DescribableList<ViewProperty,ViewPropertyDescriptor> {
private PropertyList() {
super(View.this);
public static class PropertyList extends DescribableList<ViewProperty,ViewPropertyDescriptor> {
private PropertyList(View owner) {
super(owner);
}

public PropertyList() {// needed for XStream deserialization
}

public View getOwner() {
return (View)owner;
}

@Override
protected void onModified() throws IOException {
for (ViewProperty p : this)
p.setView(View.this);
p.setView(getOwner());
}
}
}
10 changes: 10 additions & 0 deletions test/src/test/java/hudson/model/ViewTest.java
Expand Up @@ -118,4 +118,14 @@ public void testDeleteView() throws Exception {
assertNull(p.getView("list"));

}

@Bug(9367)
public void testPersistence() throws Exception {
ListView view = new ListView("foo", hudson);
hudson.addView(view);

ListView v = (ListView)Hudson.XSTREAM.fromXML(Hudson.XSTREAM.toXML(view));
System.out.println(v.getProperties());
assertNotNull(v.getProperties());
}
}

0 comments on commit dfc2fe3

Please sign in to comment.