public static StackTraceElement toStackTraceElement(String stack)
    {
        Matcher matcher = STACK_TRACE_PATTERN.matcher(stack);
        if (matcher.matches()) {
            String declaringClass = matcher.group(1);
            String methodName = matcher.group(2);
            String fileName = matcher.group(3);
            int number = -1;
            if (fileName.equals("Native Method")) {
                fileName = null;
                number = -2;
            }
            else if (matcher.group(4) != null) {
                try {
                    number = Integer.parseInt(matcher.group(4));
                }
                catch (NumberFormatException e) {
                    // Stack trace parsing is best effort.
                }
            }
            return new StackTraceElement(declaringClass, methodName, fileName, number);
        }
        return new StackTraceElement("Unknown", stack, null, -1);
    }
@Test
    public void testToStackTraceElement()
    {
        // Line number is present.
        StackTraceElement element = ExecutionFailureInfo.toStackTraceElement("at java.util.ArrayList.forEach(ArrayList.java:123)");
        assertEquals(element.getLineNumber(), 123);

        // Line number is missing.
        element = ExecutionFailureInfo.toStackTraceElement("at java.util.ArrayList.forEach(ArrayList.java)");
        assertEquals(element.getLineNumber(), -1);

        // Line number is not a number.
        element = ExecutionFailureInfo.toStackTraceElement("at java.util.ArrayList.forEach(ArrayList.java:blah)");
        assertEquals(element.getLineNumber(), -1);
    }