JStorm UI问题排查

现象

点击一个topolog的页面,发现出现错误。

java.lang.StringIndexOutOfBoundsException: String index out of range: -2
	java.lang.String.substring(String.java:1967)
	com.alibaba.jstorm.ui.tags.ErrorTag.getErrorContent(ErrorTag.java:105)
	com.alibaba.jstorm.ui.tags.ErrorTag.doTag(ErrorTag.java:62)
	org.apache.jsp.WEB_002dINF.pages.topology_jsp._jspx_meth_ct_005ferror_005f0(topology_jsp.java:1608)
	org.apache.jsp.WEB_002dINF.pages.topology_jsp._jspx_meth_c_005fforEach_005f4(topology_jsp.java:1433)
	org.apache.jsp.WEB_002dINF.pages.topology_jsp._jspService(topology_jsp.java:335)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:172)
	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
	org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

排查

直接出错的代码是

    ErrorTag.java
    private String getErrorContent() {
        List<String> ret = new ArrayList<>();
        for (ErrorEntity er : e) {
            long ts = ((long) er.getErrorTime()) * 1000;
            int index = er.getError().lastIndexOf(",");
            if (index == -1) {
                int idx = er.getError().indexOf("\n");
                int length = er.getError().length();
                if (idx != -1) {
                    String first_line = er.getError().substring(0, idx);
                    String rest_lines = er.getError().substring(idx + 1, length - 2);
                    ret.add(first_line + " , at " + UIUtils.parseDateTime(ts));
                    ret.add(rest_lines);
                }else{
                    ret.add(er.getError() + " , at " + UIUtils.parseDateTime(ts));
                }
            } else {
                ret.add(er.getError() + ", at " + UIUtils.parseDateTime(ts));
            }
        }
        Joiner joiner = Joiner.on("\n");
        return "<pre>" + joiner.join(ret) + "</pre>";
    }

具体到substring类,有三种情况抛出异常

        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        if (endIndex > value.length) {
            throw new StringIndexOutOfBoundsException(endIndex);
        }
        int subLen = endIndex - beginIndex;
        if (subLen < 0) {
            throw new StringIndexOutOfBoundsException(subLen);
        }

猜你喜欢

转载自blog.csdn.net/define_us/article/details/83029593