Skip to content

Commit

Permalink
Merge pull request #26 from milkboy/JENKINS-18229
Browse files Browse the repository at this point in the history
[JENKINS-18229] Add hack to get around the "" -> java.net.URL exception 
Yup hack but no other way to fix that :-)
  • Loading branch information
olamy committed Jun 21, 2013
2 parents deb1d45 + 815c453 commit ffd843e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/hudson/plugins/jira/JiraProjectProperty.java
Expand Up @@ -7,9 +7,13 @@
import hudson.model.JobPropertyDescriptor;
import hudson.util.CopyOnWriteList;
import net.sf.json.JSONObject;
import org.apache.commons.beanutils.Converter;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -102,7 +106,24 @@ public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData)

@Override
public boolean configure(StaplerRequest req, JSONObject formData) {
sites.replaceBy(req.bindJSONToList(JiraSite.class, formData.get("sites")));
//Fix^H^H^HDirty hack for empty string to URL conversion error
//Should check for existing handler etc, but since this is a dirty hack,
//we won't
Stapler.CONVERT_UTILS.deregister(java.net.URL.class);
Stapler.CONVERT_UTILS.register(new Converter() {
public Object convert(Class aClass, Object o) {
if(o == null || "".equals(o) || "null".equals(o)) return null;
try {
return new URL((String) o);
} catch (MalformedURLException e) {
LOGGER.warning(String.format("%s is not a valid URL.", o.toString()));
return null;
}
}
}, java.net.URL.class);
//End hack

sites.replaceBy(req.bindJSONToList(JiraSite.class, formData.get("sites")));
save();
return true;
}
Expand Down

0 comments on commit ffd843e

Please sign in to comment.