Blame SOURCES/satyr-0.13-java-suppressed-exceptions.patch

f41043
From 32085a78c063d80cc152f341343a87c8cfecfd2f Mon Sep 17 00:00:00 2001
f41043
From: Martin Milata <mmilata@redhat.com>
f41043
Date: Thu, 2 Oct 2014 16:46:30 +0200
f41043
Subject: [SATYR PATCH] java: ignore suppressed exceptions
f41043
f41043
Java exceptions can form a tree - every exception can have reference to
f41043
exception that caused it and to a list of exceptions that were
f41043
suppressed during handling[1]. We cannot take the suppressed exceptions
f41043
into account without changing the uReport format, therefore this commit
f41043
makes the java parser ignore them.
f41043
f41043
[1] http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
f41043
f41043
Fixes rhbz#1034857.
f41043
f41043
Signed-off-by: Martin Milata <mmilata@redhat.com>
f41043
---
f41043
 include/utils.h                |   3 +
f41043
 lib/java_frame.c               |  26 ++++--
f41043
 lib/utils.c                    |  16 ++++
f41043
 tests/java_stacktraces/java-04 | 185 +++++++++++++++++++++++++++++++++++++++++
f41043
 tests/python/java.py           |  12 +++
f41043
 5 files changed, 234 insertions(+), 8 deletions(-)
f41043
 create mode 100644 tests/java_stacktraces/java-04
f41043
f41043
diff --git a/include/utils.h b/include/utils.h
f41043
index 8d0a6ec..1c7984b 100644
f41043
--- a/include/utils.h
f41043
+++ b/include/utils.h
f41043
@@ -378,6 +378,9 @@ sr_skip_whitespace(const char *s);
f41043
 char *
f41043
 sr_skip_non_whitespace(const char *s);
f41043
 
f41043
+bool
f41043
+sr_skip_to_next_line_location(const char **s, int *line, int *column);
f41043
+
f41043
 /**
f41043
  * Emit a string of hex representation of bytes.
f41043
  */
f41043
diff --git a/lib/java_frame.c b/lib/java_frame.c
f41043
index da9f26b..ee97572 100644
f41043
--- a/lib/java_frame.c
f41043
+++ b/lib/java_frame.c
f41043
@@ -28,6 +28,7 @@
f41043
 #include "stacktrace.h"
f41043
 #include "internal_utils.h"
f41043
 #include <string.h>
f41043
+#include <ctype.h>
f41043
 #include <inttypes.h>
f41043
 
f41043
 #define SR_JF_MARK_NATIVE_METHOD "Native Method"
f41043
@@ -337,6 +338,10 @@ sr_java_frame_parse_exception(const char **input,
f41043
         if (strncmp("... ", cursor, strlen("... ")) == 0)
f41043
             goto current_exception_done;
f41043
 
f41043
+        /* Suppressed exceptions follow after the end of current exception */
f41043
+        if (strncmp("Suppressed: ", cursor, strlen("Suppressed: ")) == 0)
f41043
+            goto current_exception_done;
f41043
+
f41043
         /* The top most exception does not have '...' at its end */
f41043
         if (strncmp("Caused by: ", cursor, strlen("Caused by: ")) == 0)
f41043
             goto parse_inner_exception;
f41043
@@ -363,19 +368,24 @@ sr_java_frame_parse_exception(const char **input,
f41043
     goto exception_parsing_successful;
f41043
 
f41043
 current_exception_done:
f41043
-    sr_location_add(location, 0, sr_skip_char_cspan(&cursor, "\n"));
f41043
-
f41043
-    if (*cursor == '\n')
f41043
-    {
f41043
-        ++cursor;
f41043
-        /* this adds one line */
f41043
-        sr_location_add(location, 2, 0);
f41043
-    }
f41043
+    sr_skip_to_next_line_location(&cursor, &location->line, &location->column);
f41043
 
f41043
     mark = cursor;
f41043
     cursor = sr_skip_whitespace(mark);
f41043
     sr_location_add(location, 0, cursor - mark);
f41043
 
f41043
+    if (strncmp("Suppressed: ", cursor, strlen("Suppressed: ")) == 0)
f41043
+    {
f41043
+        /* Skip all lines related to the suppressed exception. We can do
f41043
+         * this by skipping all lines that begin with a whitespace - the
f41043
+         * main exception chain always begins without preceding whitespace.
f41043
+         */
f41043
+        sr_skip_to_next_line_location(&cursor, &location->line, &location->column);
f41043
+
f41043
+        while (cursor && isspace(*cursor))
f41043
+            sr_skip_to_next_line_location(&cursor, &location->line, &location->column);
f41043
+    }
f41043
+
f41043
     if (strncmp("Caused by: ", cursor, strlen("Caused by: ")) == 0)
f41043
     {
f41043
 parse_inner_exception:
f41043
diff --git a/lib/utils.c b/lib/utils.c
f41043
index 3c036f3..fa3c0a0 100644
f41043
--- a/lib/utils.c
f41043
+++ b/lib/utils.c
f41043
@@ -656,6 +656,22 @@ sr_skip_non_whitespace(const char *s)
f41043
     return (char *) s;
f41043
 }
f41043
 
f41043
+bool
f41043
+sr_skip_to_next_line_location(const char **s, int *line, int *column)
f41043
+{
f41043
+    *column += sr_skip_char_cspan(s, "\n");
f41043
+
f41043
+    if (*s && **s == '\n')
f41043
+    {
f41043
+        *column = 0;
f41043
+        (*line)++;
f41043
+        (*s)++;
f41043
+        return true;
f41043
+    }
f41043
+
f41043
+    return false;
f41043
+}
f41043
+
f41043
 char *
f41043
 sr_bin2hex(char *dst, const char *str, int count)
f41043
 {
f41043
diff --git a/tests/java_stacktraces/java-04 b/tests/java_stacktraces/java-04
f41043
new file mode 100644
f41043
index 0000000..6968eb3
f41043
--- /dev/null
f41043
+++ b/tests/java_stacktraces/java-04
f41043
@@ -0,0 +1,185 @@
f41043
+Exception in thread "main" java.lang.RuntimeException: yes
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+	at WontCatchSuppressedException.main(WontCatchSuppressedException.java:35)
f41043
+Caused by: java.lang.RuntimeException: yes
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+	... 1 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 1 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 3 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 3 more
f41043
+		Caused by: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+			... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 3 more
f41043
+		Caused by: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+			... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 1 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 3 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 3 more
f41043
+		Caused by: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+			... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 3 more
f41043
+		Caused by: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+			... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+			Suppressed: java.lang.RuntimeException: no
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+				at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+				at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+				... 5 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+Caused by: java.lang.RuntimeException: yes
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+	... 2 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 2 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:29)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 2 more
f41043
+	Caused by: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+		... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+		Suppressed: java.lang.RuntimeException: no
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+			at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+			at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+			... 4 more
f41043
+Caused by: java.lang.RuntimeException: yes
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+	at WontCatchSuppressedException.die(WontCatchSuppressedException.java:27)
f41043
+	... 3 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 3 more
f41043
+	Suppressed: java.lang.RuntimeException: no
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:23)
f41043
+		at WontCatchSuppressedException.close(WontCatchSuppressedException.java:16)
f41043
+		at WontCatchSuppressedException.die(WontCatchSuppressedException.java:28)
f41043
+		... 3 more
f41043
diff --git a/tests/python/java.py b/tests/python/java.py
f41043
index 3b85c18..1156fb6 100755
f41043
--- a/tests/python/java.py
f41043
+++ b/tests/python/java.py
f41043
@@ -152,6 +152,18 @@ class TestJavaStacktrace(BindingsTestCase):
f41043
     def test_hash(self):
f41043
         self.assertHashable(self.trace)
f41043
 
f41043
+    def test_suppressed(self):
f41043
+        contents = load_input_contents('../java_stacktraces/java-04')
f41043
+        trace = satyr.JavaStacktrace(contents)
f41043
+
f41043
+        names = 4*['java.lang.RuntimeException', 'WontCatchSuppressedException.die', 'WontCatchSuppressedException.die']
f41043
+        names[-1] = 'WontCatchSuppressedException.main'
f41043
+        msgs = 4*['yes', None, None]
f41043
+
f41043
+        for frame, name, msg in zip(trace.threads[0].frames, names, msgs):
f41043
+            self.assertEqual(frame.name, name)
f41043
+            self.assertEqual(frame.message, msg)
f41043
+
f41043
 class TestJavaThread(BindingsTestCase):
f41043
     def setUp(self):
f41043
         self.thread = satyr.JavaStacktrace(contents).threads[0]
f41043
-- 
f41043
1.9.3
f41043