@Test public void testStackTraceWithCause() { String input = "org.apache.commons.lang3.SerializationException: ClassNotFoundException " + "while reading cloned object data\n" + "\tat org.apache.commons.lang3.SerializationUtils.<init>(SerializationUtils.java:99)\n" + "Caused by: java.lang.ClassNotFoundException: byte\n" + "\tat org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1365)\n" + "\tat java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)\n"; String cause = "java.lang.ClassNotFoundException: byte\n" + "\tat org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1365)\n" + "\tat java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)\n"; List<CrashStackTrace> stackTraces = StackTracesParsing.parseStackTraces(input); assertThat(stackTraces, hasSize(1)); CrashStackTrace st = stackTraces.get(0); LOG.trace("Stack trace is {}", st); assertThat(st.getExceptionClass(), equalTo("org.apache.commons.lang3.SerializationException")); assertThat(st.getErrorMessage(), equalTo("ClassNotFoundException while reading cloned object data")); assertThat(st.highestFrameLevel(), equalTo(1)); assertThat(st.getCause(), notNullValue()); CrashStackTrace causeSt = StackTracesParsing.parseStackTraces(cause).get(0); assertThat(st.getCause(), equalTo(causeSt)); }
public static List<CrashStackTrace> parseStackTraces(String input){ CharStream text = CharStreams.fromString(input); StackTracesLexer lexer = new StackTracesLexer(text); CommonTokenStream tokens = new CommonTokenStream(lexer); StackTracesParser parser = new StackTracesParser(tokens); StackTracesParser.StackTracesContext tree = parser.stackTraces(); StackTracesCollectorListener listener = new StackTracesCollectorListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, tree); return listener.getStackTraces(); }
StackTracesParsing { public static List<CrashStackTrace> parseStackTraces(String input){ CharStream text = CharStreams.fromString(input); StackTracesLexer lexer = new StackTracesLexer(text); CommonTokenStream tokens = new CommonTokenStream(lexer); StackTracesParser parser = new StackTracesParser(tokens); StackTracesParser.StackTracesContext tree = parser.stackTraces(); StackTracesCollectorListener listener = new StackTracesCollectorListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, tree); return listener.getStackTraces(); } }
StackTracesParsing { public static List<CrashStackTrace> parseStackTraces(String input){ CharStream text = CharStreams.fromString(input); StackTracesLexer lexer = new StackTracesLexer(text); CommonTokenStream tokens = new CommonTokenStream(lexer); StackTracesParser parser = new StackTracesParser(tokens); StackTracesParser.StackTracesContext tree = parser.stackTraces(); StackTracesCollectorListener listener = new StackTracesCollectorListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, tree); return listener.getStackTraces(); }  }
StackTracesParsing { public static List<CrashStackTrace> parseStackTraces(String input){ CharStream text = CharStreams.fromString(input); StackTracesLexer lexer = new StackTracesLexer(text); CommonTokenStream tokens = new CommonTokenStream(lexer); StackTracesParser parser = new StackTracesParser(tokens); StackTracesParser.StackTracesContext tree = parser.stackTraces(); StackTracesCollectorListener listener = new StackTracesCollectorListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, tree); return listener.getStackTraces(); }  static List<CrashStackTrace> parseStackTraces(String input); }
StackTracesParsing { public static List<CrashStackTrace> parseStackTraces(String input){ CharStream text = CharStreams.fromString(input); StackTracesLexer lexer = new StackTracesLexer(text); CommonTokenStream tokens = new CommonTokenStream(lexer); StackTracesParser parser = new StackTracesParser(tokens); StackTracesParser.StackTracesContext tree = parser.stackTraces(); StackTracesCollectorListener listener = new StackTracesCollectorListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, tree); return listener.getStackTraces(); }  static List<CrashStackTrace> parseStackTraces(String input);  }