Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-7034] auto-recover from corrupt update data.
  • Loading branch information
kohsuke committed Sep 17, 2011
1 parent 6224262 commit ce7300c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Recover from a corrupted JSON update data file automatically
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-7034">issue 7034</a>)
<li class=bug>
Fixed the reported system reboot problem on installing JDK on Windows
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-7288">issue 7288</a>)
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/hudson/model/DownloadService.java
Expand Up @@ -26,15 +26,18 @@
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.util.IOException2;
import hudson.util.IOUtils;
import hudson.util.QuotedStringTokenizer;
import hudson.util.TextFile;
import hudson.util.TimeUnit2;
import jenkins.model.Jenkins;
import net.sf.json.JSONException;
import org.kohsuke.stapler.Stapler;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.json.JSONObject;
Expand Down Expand Up @@ -206,7 +209,12 @@ public long getDue() {
public JSONObject getData() throws IOException {
TextFile df = getDataFile();
if(df.exists())
return JSONObject.fromObject(df.read());
try {
return JSONObject.fromObject(df.read());
} catch (JSONException e) {
df.delete(); // if we keep this file, it will cause repeated failures
throw new IOException2("Failed to parse "+df+" into JSON",e);
}
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/model/UpdateSite.java
Expand Up @@ -36,6 +36,7 @@
import hudson.util.TextFile;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.io.output.TeeOutputStream;
Expand Down Expand Up @@ -264,6 +265,10 @@ public JSONObject getJSONObject() {
if(df.exists()) {
try {
return JSONObject.fromObject(df.read());
} catch (JSONException e) {
LOGGER.log(Level.SEVERE,"Failed to parse "+df,e);
df.delete(); // if we keep this file, it will cause repeated failures
return null;
} catch (IOException e) {
LOGGER.log(Level.SEVERE,"Failed to parse "+df,e);
df.delete(); // if we keep this file, it will cause repeated failures
Expand Down

0 comments on commit ce7300c

Please sign in to comment.