Skip to content

Commit

Permalink
Merge pull request #1692 from daspilker/JENKINS-28292
Browse files Browse the repository at this point in the history
[JENKINS-28292] fixed synchronization issue when setting JDK installations
  • Loading branch information
oleg-nenashev committed Jun 13, 2015
2 parents 3f0e292 + 44eeb10 commit 67f4dd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 2 additions & 5 deletions core/src/main/java/hudson/model/JDK.java
Expand Up @@ -166,11 +166,8 @@ public String getDisplayName() {
return Jenkins.getInstance().getJDKs().toArray(new JDK[0]);
}

// this isn't really synchronized well since the list is Hudson.jdks :(
public @Override synchronized void setInstallations(JDK... jdks) {
List<JDK> list = Jenkins.getInstance().getJDKs();
list.clear();
list.addAll(Arrays.asList(jdks));
public @Override void setInstallations(JDK... jdks) {
Jenkins.getInstance().setJDKs(Arrays.asList(jdks));
}

@Override
Expand Down
16 changes: 13 additions & 3 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -1640,12 +1640,23 @@ public String getDisplayName() {
return Messages.Hudson_DisplayName();
}

public List<JDK> getJDKs() {
public synchronized List<JDK> getJDKs() {
if(jdks==null)
jdks = new ArrayList<JDK>();
return jdks;
}

/**
* Replaces all JDK installations with those from the given collection.
*
* Use {@link hudson.model.JDK.DescriptorImpl#setInstallations(JDK...)} to
* set JDK installations from external code.
*/
@Restricted(NoExternalUse.class)
public synchronized void setJDKs(Collection<? extends JDK> jdks) {
this.jdks = new ArrayList<JDK>(jdks);
}

/**
* Gets the JDK installation of the given name, or returns null.
*/
Expand Down Expand Up @@ -2852,8 +2863,7 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp

systemMessage = Util.nullify(req.getParameter("system_message"));

jdks.clear();
jdks.addAll(req.bindJSONToList(JDK.class,json.get("jdks")));
setJDKs(req.bindJSONToList(JDK.class, json.get("jdks")));

boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified())
Expand Down

0 comments on commit 67f4dd5

Please sign in to comment.