mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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