mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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