From 396a88701b26bd9f98b44d37a102f33f36462436 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 13 Mar 2020 10:59:25 +0100 Subject: [PATCH] fix java:S2259 possible NPE --- .../util/cache/ProtobufIssueDiskCache.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java index 3dc527a31ad..602981259fc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java @@ -27,6 +27,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; +import java.io.Serializable; import java.util.Collections; import java.util.Date; import java.util.Map; @@ -247,11 +248,13 @@ public class ProtobufIssueDiskCache implements DiskCache { for (Map.Entry e : fieldDiffs.diffs().entrySet()) { IssueCache.Diff.Builder diffBuilder = IssueCache.Diff.newBuilder(); - if (e.getValue().oldValue() != null) { - diffBuilder.setOldValue(e.getValue().oldValue().toString()); + Serializable oldValue = e.getValue().oldValue(); + if (oldValue != null) { + diffBuilder.setOldValue(oldValue.toString()); } - if (e.getValue().newValue() != null) { - diffBuilder.setNewValue(e.getValue().newValue().toString()); + Serializable newValue = e.getValue().newValue(); + if (newValue != null) { + diffBuilder.setNewValue(newValue.toString()); } builder.putDiffs(e.getKey(), diffBuilder.build()); -- 2.39.5