From d32ddbb41fd2631960a63983b202d97d2ad50dc4 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Tue, 19 Feb 2019 14:30:15 -0800 Subject: [PATCH] Prevent NPE when original source content is missing Closes #3234 Closes https://github.com/google/closure-compiler/pull/3235. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=234675335 --- .../google/debugging/sourcemap/SourceMapGeneratorV3.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/google/debugging/sourcemap/SourceMapGeneratorV3.java b/src/com/google/debugging/sourcemap/SourceMapGeneratorV3.java index 48dfea9e08d..ce64f8fd683 100644 --- a/src/com/google/debugging/sourcemap/SourceMapGeneratorV3.java +++ b/src/com/google/debugging/sourcemap/SourceMapGeneratorV3.java @@ -17,6 +17,7 @@ package com.google.debugging.sourcemap; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Strings.nullToEmpty; import com.google.common.base.Preconditions; import com.google.debugging.sourcemap.SourceMapConsumerV3.EntryVisitor; @@ -29,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import javax.annotation.Nullable; /** @@ -508,7 +510,8 @@ private void addSourcesContentMap(Appendable out) throws IOException { if (i != 0) { out.append(","); } - out.append(escapeString(contents.get(i))); + String sourceContent = contents.get(i); + out.append(escapeString(nullToEmpty(sourceContent))); } out.append("]"); appendFieldEnd(out); @@ -856,7 +859,7 @@ private static void appendOffsetValue(Appendable out, int line, int column) thro } private int getSourceId(String sourceName) { - if (sourceName != lastSourceFile) { + if (!Objects.equals(sourceName, lastSourceFile)) { lastSourceFile = sourceName; Integer index = sourceFileMap.get(sourceName); if (index != null) {