From beb8ba239f52121f1bef4f7093c5f2a1f0384d46 Mon Sep 17 00:00:00 2001 From: Michael Barrientos Date: Fri, 3 Mar 2017 08:34:36 -0800 Subject: [PATCH 1/2] Findbugs fixes --- .../java/hudson/plugins/cobertura/CoberturaPublisher.java | 7 ++++--- .../hudson/plugins/cobertura/targets/CoverageTarget.java | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java index 355a7416..c2986e9f 100644 --- a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java +++ b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java @@ -694,9 +694,10 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc */ @Override public CoberturaPublisher newInstance(StaplerRequest req, JSONObject formData) throws FormException { - if (req == null) { - return null; - } + // Null check because findbugs insists, despite the API guaranteeing this is never null. + if (req == null) { + throw new FormException("req cannot be null", ""); + } CoberturaPublisher instance = req.bindJSON(CoberturaPublisher.class, formData); ConvertUtils.register(CoberturaPublisherTarget.CONVERTER, CoverageMetric.class); List targets = req diff --git a/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java b/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java index c4934f46..039430eb 100644 --- a/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java +++ b/src/main/java/hudson/plugins/cobertura/targets/CoverageTarget.java @@ -106,13 +106,12 @@ public Map getRangeScores(CoverageTarget min, CoverageR } public Map getRangeScores(CoverageTarget min, Map results) { - Integer j; Map result = new EnumMap(CoverageMetric.class); for (Map.Entry target : this.targets.entrySet()) { Ratio observed = results.get(target.getKey()); if (observed != null) { - j = CoverageTarget.calcRangeScore(target.getValue() / 100000, min.targets.get(target.getKey()), observed.getPercentage()); - result.put(target.getKey(), j); + int j = CoverageTarget.calcRangeScore(target.getValue() / 100000, min.targets.get(target.getKey()), observed.getPercentage()); + result.put(target.getKey(), Integer.valueOf(j)); } } return result; From 4cdc2161945f0e7428aa8b5d0c2949903743a44b Mon Sep 17 00:00:00 2001 From: Michael Barrientos Date: Tue, 25 Apr 2017 09:15:51 -0700 Subject: [PATCH 2/2] Restore deleted code --- .../java/hudson/plugins/cobertura/CoberturaPublisher.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java index c2986e9f..47b941f8 100644 --- a/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java +++ b/src/main/java/hudson/plugins/cobertura/CoberturaPublisher.java @@ -385,6 +385,13 @@ public void perform(Run build, FilePath workspace, Launcher launcher, fina FilePath[] reports = null; try { reports = workspace.act(new ParseReportCallable(coberturaReportFile)); + + // if the build has failed, then there's not + // much point in reporting an error + if (buildResult != null && buildResult.isWorseOrEqualTo(Result.FAILURE) && reports.length == 0) { + return; + } + } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError("Unable to find coverage results"));