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.
Cherry-picked-from: ce7300c
  • Loading branch information
kohsuke committed Oct 21, 2011
1 parent 51ba1be commit 5f07ed7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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 @@ -210,7 +213,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 5f07ed7

Please sign in to comment.