diff --git a/changelog.html b/changelog.html
index 05ff9b16e3..dac3b7a117 100644
--- a/changelog.html
+++ b/changelog.html
@@ -60,6 +60,9 @@ Upcoming changes
+ -
+ Fixed a bug in persisting user configuration that causes NPE in some plugins
+ (issue 9062)
-
Replacement of some maven properties is not working
(issue 8573)
diff --git a/core/src/main/java/hudson/model/User.java b/core/src/main/java/hudson/model/User.java
index 84eebf84b0..522e177483 100644
--- a/core/src/main/java/hudson/model/User.java
+++ b/core/src/main/java/hudson/model/User.java
@@ -455,7 +455,8 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
p.setUser(this);
}
- props.add(p);
+ if (p!=null)
+ props.add(p);
}
this.properties = props;
diff --git a/test/src/test/java/hudson/model/UserPropertyTest.java b/test/src/test/java/hudson/model/UserPropertyTest.java
new file mode 100644
index 0000000000..87474b69f0
--- /dev/null
+++ b/test/src/test/java/hudson/model/UserPropertyTest.java
@@ -0,0 +1,52 @@
+package hudson.model;
+
+import org.jvnet.hudson.test.Bug;
+import org.jvnet.hudson.test.HudsonTestCase;
+import org.jvnet.hudson.test.TestExtension;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class UserPropertyTest extends HudsonTestCase {
+ @Bug(9062)
+ public void test9062() throws Exception {
+ User u = User.get("foo");
+ u.addProperty(new UserProperty1());
+ configRoundtrip(u);
+ for (UserProperty p : u.getAllProperties())
+ assertNotNull(p);
+ }
+
+ public static class UserProperty1 extends UserProperty {
+ @TestExtension
+ public static class DescriptorImpl extends UserPropertyDescriptor {
+ public String getDisplayName() {
+ return "UserProperty1";
+ }
+
+ @Override
+ public UserProperty newInstance(User user) {
+ return new UserProperty1();
+ }
+ }
+ }
+
+ public static class UserProperty2 extends UserProperty {
+ @TestExtension
+ public static class DescriptorImpl extends UserPropertyDescriptor {
+ public String getDisplayName() {
+ return "UserProperty2";
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return false;
+ }
+
+ @Override
+ public UserProperty newInstance(User user) {
+ return new UserProperty1();
+ }
+ }
+ }
+}
diff --git a/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty1/config.jelly b/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty1/config.jelly
new file mode 100644
index 0000000000..b5425226ee
--- /dev/null
+++ b/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty1/config.jelly
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty2/config.jelly b/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty2/config.jelly
new file mode 100644
index 0000000000..b5425226ee
--- /dev/null
+++ b/test/src/test/resources/hudson/model/UserPropertyTest/UserProperty2/config.jelly
@@ -0,0 +1 @@
+
\ No newline at end of file