Skip to content
Permalink
Browse files

[FIXED JENKINS-7034] auto-recover from corrupt update data.

  • Loading branch information
kohsuke committed Sep 17, 2011
1 parent 6224262 commit ce7300cdf672c58a9b4456f5f0bdc3288e152427
@@ -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>)
@@ -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;
@@ -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;
}

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

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