Skip to content

Commit

Permalink
[FIXED JENKINS-9062] Fixed a bug in persisting user configuration tha…
Browse files Browse the repository at this point in the history
…t causes NPE in some plugins
  • Loading branch information
kohsuke committed Mar 19, 2011
1 parent 08b7541 commit 29dc1d5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -60,6 +60,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Fixed a bug in persisting user configuration that causes NPE in some plugins
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9062">issue 9062</a>)
<li class=bug>
Replacement of some maven properties is not working
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-8573">issue 8573</a>)
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/User.java
Expand Up @@ -455,7 +455,8 @@ public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOE
p.setUser(this);
}

props.add(p);
if (p!=null)
props.add(p);
}
this.properties = props;

Expand Down
52 changes: 52 additions & 0 deletions 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();
}
}
}
}
@@ -0,0 +1 @@
<j:jelly xmlns:j="jelly:core"/>
@@ -0,0 +1 @@
<j:jelly xmlns:j="jelly:core"/>

0 comments on commit 29dc1d5

Please sign in to comment.