Skip to content

Commit

Permalink
JENKINS-23708: Fix NullPointerException when the transient logger is …
Browse files Browse the repository at this point in the history
…not populated during de-serialization
  • Loading branch information
centic9 committed Nov 29, 2014
1 parent c1b432f commit 7e9117a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java
Expand Up @@ -39,7 +39,7 @@ public final class JacocoBuildAction extends CoverageObject<JacocoBuildAction> i

@Deprecated public transient AbstractBuild<?,?> build;

public final transient PrintStream logger;
private final transient PrintStream logger;
@Deprecated private transient ArrayList<?> reports;
private transient WeakReference<CoverageReport> report;
private final String[] inclusions;
Expand Down Expand Up @@ -229,8 +229,8 @@ public synchronized CoverageReport getResult() {
r.setThresholds(thresholds);
return r;
} catch (IOException e) {
logger.println("Failed to load " + reportFolder);
e.printStackTrace(logger);
getLogger().println("Failed to load " + reportFolder);
e.printStackTrace(getLogger());
return null;
}
}
Expand Down Expand Up @@ -318,5 +318,14 @@ private static Map<Type, Coverage> loadRatios(JacocoReportDir layout, Map<Type,

}

//private static final Logger logger = Logger.getLogger(JacocoBuildAction.class.getName());
//private static final Logger logger = Logger.getLogger(JacocoBuildAction.class.getName());
public final PrintStream getLogger() {
if(logger != null) {
return logger;
}

// use System.out as a fallback if the BuildAction was de-serialized which
// does not run the construct and thus leaves the transient variables empty
return System.out;
}
}
Expand Up @@ -21,8 +21,8 @@
import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.analysis.IMethodCoverage;
import org.jacoco.core.analysis.IPackageCoverage;
import org.jacoco.core.tools.ExecFileLoader;
import org.jacoco.core.data.ExecutionDataWriter;
import org.jacoco.core.tools.ExecFileLoader;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down Expand Up @@ -62,7 +62,7 @@ public CoverageReport(JacocoBuildAction action, ExecutionFileLoader executionFil
this(action);
try {

action.logger.println("[JaCoCo plugin] Loading packages..");
action.getLogger().println("[JaCoCo plugin] Loading packages..");

if (executionFileLoader.getBundleCoverage() !=null ) {
setAllCovTypes(this, executionFileLoader.getBundleCoverage());
Expand Down Expand Up @@ -100,7 +100,7 @@ public CoverageReport(JacocoBuildAction action, ExecutionFileLoader executionFil
this.add(packageReport);
}
}
action.logger.println("[JaCoCo plugin] Done.");
action.getLogger().println("[JaCoCo plugin] Done.");

} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 7e9117a

Please sign in to comment.