diff --git a/src/main/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapter.java b/src/main/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapter.java index 71fcbbbe9..5fb82e616 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapter.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapter.java @@ -87,35 +87,37 @@ private Tag generateGeneralTableHtml(final String executable, final String uniqu } private Tag maybeGenerateStackTracesHtml(@CheckForNull final String stacksJson, final String message, @CheckForNull final JSONArray auxWhats) { - ContainerTag stackTraces = null; - - if (StringUtils.isNotBlank(stacksJson)) { - final JSONArray stacks = new JSONArray(new JSONTokener(stacksJson)); + if (StringUtils.isBlank(stacksJson)) { + return iff(false, null); + } - if (!stacks.isEmpty()) { - stackTraces = div(); + final JSONArray stacks = new JSONArray(new JSONTokener(stacksJson)); - stackTraces.with(generateStackTraceHtml("Primary Stack Trace", message, stacks.getJSONArray(0))); + if (!stacks.isEmpty()) { + ContainerTag stackTraces = div(); - for (int stackIndex = 1; stackIndex < stacks.length(); ++stackIndex) { - String msg = null; + stackTraces.with(generateStackTraceHtml("Primary Stack Trace", message, stacks.getJSONArray(0))); - if (auxWhats != null && auxWhats.length() >= stackIndex) { - msg = auxWhats.getString(stackIndex - 1); - } + for (int stackIndex = 1; stackIndex < stacks.length(); ++stackIndex) { + String msg = null; - String title = "Auxiliary Stack Trace"; + if (auxWhats != null && auxWhats.length() >= stackIndex) { + msg = auxWhats.getString(stackIndex - 1); + } - if (stacks.length() > NUMBERED_STACK_THRESHOLD) { - title += " #" + stackIndex; - } + String title = "Auxiliary Stack Trace"; - stackTraces.with(generateStackTraceHtml(title, msg, stacks.getJSONArray(stackIndex))); + if (stacks.length() > NUMBERED_STACK_THRESHOLD) { + title += " #" + stackIndex; } + + stackTraces.with(generateStackTraceHtml(title, msg, stacks.getJSONArray(stackIndex))); } + + return stackTraces; } - return stackTraces; + return iff(false, null); } private Tag generateStackTraceHtml(final String title, @CheckForNull final String message, final JSONArray frames) { @@ -162,7 +164,6 @@ private Tag maybeGenerateTableRowHtml(final String name, @CheckForNull final Str } private Tag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) throws JSONException { - Tag row = null; final String file = frame.optString("file"); if (StringUtils.isNotBlank(file)) { @@ -180,10 +181,10 @@ private Tag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) thro fileBuilder.append(':').append(line); } - row = maybeGenerateTableRowHtml("File", fileBuilder.toString()); + return maybeGenerateTableRowHtml("File", fileBuilder.toString()); } - return row; + return iff(false, null); } @CheckForNull diff --git a/src/test/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapterTest.java b/src/test/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapterTest.java index a753839bd..1f02c1550 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapterTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/violations/ValgrindAdapterTest.java @@ -61,12 +61,12 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti report.forEach( issue -> { final String description = issue.getDescription(); - - if (!issue.getFileName().equals(Violation.NO_FILE)) { + if (Violation.NO_FILE.equals(issue.getFileName())) { + assertThat(!description.contains("Primary Stack Trace")); + } + else { assertThat(description.contains("Primary Stack Trace")); assertThat(description.contains("<insert_a_suppression_name_here>")); - } else { - assertThat(!description.contains("Primary Stack Trace")); } } );