From dfc2fe3895a1284d74da9658082ca5aaa4cc63b6 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 18 Apr 2011 09:42:18 -0700 Subject: [PATCH] [FIXED JENKINS-9367] persistence problem in View$PropertyList --- changelog.html | 4 +++- core/src/main/java/hudson/model/ListView.java | 3 ++- core/src/main/java/hudson/model/View.java | 23 +++++++++++++------ test/src/test/java/hudson/model/ViewTest.java | 10 ++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/changelog.html b/changelog.html index 3827f2d5bb..54d5d09372 100644 --- a/changelog.html +++ b/changelog.html @@ -55,7 +55,9 @@ Upcoming changes diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index e06110b0e2..4167702551 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -91,7 +91,8 @@ public class ListView extends View implements Saveable { this.owner = owner; } - private Object readResolve() { + protected Object readResolve() { + super.readResolve(); if(includeRegex!=null) includePattern = Pattern.compile(includeRegex); initColumns(); diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index ed40898026..4fc4a968e0 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -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 properties = new PropertyList(); + private volatile DescribableList properties = new PropertyList(this); protected View(String name) { this.name = name; @@ -129,9 +129,11 @@ public abstract class View extends AbstractModelObject implements AccessControll 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; } @@ -762,15 +764,22 @@ public abstract class View extends AbstractModelObject implements AccessControll return v; } - private class PropertyList extends DescribableList { - private PropertyList() { - super(View.this); + public static class PropertyList extends DescribableList { + 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()); } } } diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java index d379362c6e..b21fe5a5e9 100644 --- a/test/src/test/java/hudson/model/ViewTest.java +++ b/test/src/test/java/hudson/model/ViewTest.java @@ -118,4 +118,14 @@ public class ViewTest extends HudsonTestCase { 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()); + } }