Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-73648

NPE is produced in SAXReader.read() call in case of having a portlet with dom4j library

    Details

    • Fix Priority:
      4

      Description


      ee-6.2.x: reproduced
      ee-7.0.x: not reproduced
      master: not reproduced
      new OSGI infrastructure solves the issue in 7.0.x and upper versions


      Due to LPS-71278 code, in case of having a portlet with dom4j library, a NPE is produced in case of calling to org.dom4j.io.SAXReader.read() method

      Steps to reproduce

      1. Install test-dom4j-portlet.war portlet (attached to JIRA ticket)
      2. Add test dom4j portlet to any page
      3. - Expected behavior: a test message with a xml is displayed in portlet
      4. - Wrong behavior: an exception is thrown in log file
        18:11:30,902 ERROR [RuntimePageImpl-1][render_portlet_jsp:132] null
        org.dom4j.DocumentException: null Nested exception: null
        	at org.dom4j.io.SAXReader.read(SAXReader.java:484)
        	at org.dom4j.io.SAXReader.read(SAXReader.java:343)
        	at org.apache.jsp.view_jsp._jspService(view_jsp.java:140)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:117)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
        	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
        	at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:331)
        	at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:112)
        Nested exception: 
        java.lang.NullPointerException
        	at org.dom4j.tree.NamespaceStack.createNamespace(NamespaceStack.java:407)
        	at org.dom4j.tree.NamespaceStack.getQName(NamespaceStack.java:211)
        	at org.dom4j.io.SAXContentHandler.startElement(SAXContentHandler.java:234)
        	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
        	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:380)
        	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:614)
        	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3135)
        	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
        	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
        	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
        	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
        	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
        	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
        	at org.dom4j.io.SAXReader.read(SAXReader.java:465)
        	at org.dom4j.io.SAXReader.read(SAXReader.java:343)
        	at org.apache.jsp.view_jsp._jspService(view_jsp.java:140)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:117)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
        	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
        	at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:331)
        	at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:112)
        	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:362)
        	at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:378)
        	at com.liferay.util.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:144)
        	at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:235)
        	at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:314)
        	at javax.portlet.GenericPortlet.render(GenericPortlet.java:262)
        	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
        	at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
        	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
        	at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
        	at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:117)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
        	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
        	at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:588)
        	at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:662)
        	at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:369)
        	at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1238)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
        	at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:117)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
        	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
        	at com.liferay.portal.servlet.DirectServletPathRegisterDispatcher.include(DirectServletPathRegisterDispatcher.java:55)
        	at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
        	at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
        	at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:638)
        	at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:135)
        	at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
        	at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
        	at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
        	at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:125)
        	at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
        	at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:180)
        	at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
        	at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
        	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        	at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
        	at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
        	at java.lang.Thread.run(Thread.java:745)
        

      Root cause of the issue:

      • In LPS-71278 a new com.liferay.portal.xml.DocumentFactory was added for dom4j (see system.properties file)
      • But that class is inside portal-impl.jar, so cannot be instantiated from portlets

      Solution:

      1. Revert system.properties changes: add org.dom4j.factory=org.dom4j.DocumentFactory to system-ext.properties configuration file
      2. Change the custom code to use our utils and wrappers for dom4j classes:
        <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
        
        <%@ page import="java.io.*" %>
        <%@ page import="java.util.*" %>
        
        <%@ page import="com.liferay.portal.kernel.util.*" %>
        <%@ page import="com.liferay.portal.kernel.xml.*" %>
        
        <portlet:defineObjects />
        
        <%
        String xmlString = "<root><text>test</text><text>test</text></root>";
        
        InputStream xmlInputStream = new ByteArrayInputStream(xmlString.getBytes());
        
        Document document = SAXReaderUtil.read(xmlInputStream);
        %>
        
        XML: <pre><%=HtmlUtil.escape(xmlString)%></pre><br/>
        Document: <%=document%><br/>
        

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jorge.diaz Jorge Diaz
                Reporter:
                jorge.diaz Jorge Diaz
                Participants of an Issue:
                Recent user:
                Enterprise Release HU
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  1 year, 40 weeks, 3 days ago

                  Packages

                  Version Package