Omnifaces 1.8.1 WebXML 解析异常

Omnifaces 1.8.1 WebXML parse exception

我在尝试调用从 org.w3c.dom.Node.getTextContent() 返回的对象的方法 java.lang.String.trim() 时收到 java.lang.NullPointerException:

当我使用

List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles(); 

来自 ManagedBean,如下所示:

@ManagedBean
@RequestScoped
public class LogoffControl implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * log4j logger
     */
    protected static final Logger LOGGER = LogFactory
            .getLogger(LogoffControl.class);

    public String logoff() {
        List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();
        try {
            Faces.redirect(welcomeFiles.get(0));
        } catch (IOException e) {
            LOGGER.error("Redirect Failed: " + e.getMessage());
        }
        Faces.invalidateSession();
        return "";
    }
}

我收到 NullPointerException,说我的 web.xml 可能有错字。我已经调试过了,在WebXML.java行414看到xpath执行的结果成功,在418行

进入循环
welcomeFiles.add(welcomeFileList.item(i).getTextContent().trim());  

在调试器中 welcomeFileList.item(i) 的计算结果为 <welcome-file>index.jsp</welcome-file>,但是调用 welcomeFileList.item(i).getTextContent() 结果为空。我想不通...我错过了什么?

在日志中:

Jan 11, 2015 1:36:37 PM org.omnifaces.config.WebXml init
SEVERE: WebXml failed to initialize. Perhaps your web.xml contains a typo?
java.lang.NullPointerException: while trying to invoke the method java.lang.String.trim() of an object returned from org.w3c.dom.Node.getTextContent()
at org.omnifaces.config.WebXml.parseWelcomeFiles(WebXml.java:418

Oracle JSF 2.1.26、Omnifaces 1.8.1、servlet 2.5、sapjvm6.1 (Java6),在 SAPNetweaver 7.4 服务器上。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>tablemaint-web</display-name>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    ....
</webapp>

这是所用 JAXP 解析器中的错误。这应该可以正常工作。 SAP JAXP 解析器显然无法将文本节点识别为文本节点。 getTextContent() 即 return null 例如文档节点和文档类型节点。

使用 getFirstChild().getNodeValue() 而不是 getTextContent() 的变通方法似乎工作正常(并且应该继续在体面的 JAXP 解析器上正常工作),所以这 implemented and the fix is available in today's 1.11 snapshot (and 2.1 snapshot 2.x 用户)。