Skip to content
Permalink
Browse files

[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 5f07ed7c96f50193af00f7c9c7e4197ed016c5bd
@@ -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;
@@ -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;
}

@@ -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;
@@ -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

0 comments on commit 5f07ed7

Please sign in to comment.
You can’t perform that action at this time.