對異常絕不要輕易喫掉

最近項目中發現解釋XML的時候一直報空指針,很愁人,最後反編譯看代碼後終於找到問題的根源了:

 

borlandxml.jar裏有個類:com.borland.xml.toolkit.XmlUtil對異常處理極爲不友好,如下:

    public static Element getDocRootElement(InputStream inputstream)

    {

        try

        {

            Element element = new Element(isSAXUsed() ? getSAX().build(inputstream).getRootElement() : getDOM().build(inputstream).getRootElement());

            return element;

        }

        catch(JDOMException jdomexception)

        {

            Element element1 = null;

//這裏把異常自己喫掉了。我在執行程序的時候,報:org.jdom.JDOMException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found錯,

//明顯是少包的問題,像這種異常,如果不反編譯進來很難發現(如果使用POM.XML管理依賴也行)

            return element1;

        }

        finally

        {

           

        }

    }

///////////////////

加入xercesImpl.jar問題解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章