From 1c1fb04a3997dc6ed6e1b9c9006d591bcde6e269 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 12 Jul 2016 16:00:13 +0200 Subject: [PATCH] Do not hide exception when fail to close json --- .../java/org/sonar/api/utils/text/JsonWriter.java | 3 +-- .../java/org/sonar/api/utils/text/JsonWriterTest.java | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java index bea1dcc2d27..de3b3cd988d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java @@ -382,8 +382,7 @@ public class JsonWriter { } private static IllegalStateException rethrow(Exception e) { - // stacktrace is not helpful - throw new WriterException("Fail to write JSON: " + e.getMessage()); + throw new WriterException("Fail to write JSON", e); } @Nullable diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java index 8c853620404..0ed59a44c00 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java @@ -20,17 +20,16 @@ package org.sonar.api.utils.text; import com.google.common.collect.ImmutableMap; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.DateUtils; - import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; import java.util.Date; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.DateUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -208,7 +207,7 @@ public class JsonWriterTest { com.google.gson.stream.JsonWriter gson = mock(com.google.gson.stream.JsonWriter.class); when(gson.beginArray()).thenThrow(new IOException("the reason")); thrown.expect(WriterException.class); - thrown.expectMessage("Fail to write JSON: the reason"); + thrown.expectMessage("Fail to write JSON"); new JsonWriter(gson).beginArray(); } -- 2.39.5