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

Using PropertyConfigurator (Log4j) in a module/custom portlet causes NoSuchMethodError

    Details

      Description

      Log4j PropertyConfigurator#configure(InputStream) error message on deploying custom portlet.

      Steps to Reproduce (7.x, master):
      1. Start up a vanilla DXP SP 6 bundle.
      2. Deploy attached cnp.test.log4j.jar.
      3. Place a cnp-test-log4j portlet on the welcome page.

      Result: Portlet crashes on UI and and the log complains:

      java.lang.NoSuchMethodError: org.apache.log4j.PropertyConfigurator.configure(Ljava/io/InputStream;)V
      	at cnp.test.log4j.portlet.CnpTestLog4jPortlet.render(CnpTestLog4jPortlet.java:43)
      	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
      ...
      

      Steps to Reproduce (6.2.x)

      1. Create a dummy portlet with Liferay IDE/Plugins SDK. I'm using use one of the standard plugins of Liferay as a boilerplate code, e.g. https://github.com/liferay/liferay-plugins/tree/6.2.x/portlets/calendar-portlet
      2. Add the following code to the #render method of the Portlet class, for example
        com.liferay.calendar.portlet.CalendarPortlet.render(RenderRequest, RenderResponse)
        		try {
        			InputStream is = this.getClass().getClassLoader().getResourceAsStream("log_arcade.properties");
        			PropertyConfigurator.configure(is);
        		} catch (Throwable e) {
        			// TODO Auto-generated catch block
        			e.printStackTrace();
        			
        			throw new PortletException(e);
        		}
        
      3. Add missing Import: import org.apache.log4j.PropertyConfigurator;
      4. Start 6.2.x
      5. Build the plugin
      6. Add Calendar Porlet to a page
        Result:
        15:37:24,522 ERROR [http-bio-6211-exec-1][render_portlet_jsp:132] null
        java.lang.NoSuchMethodError: org.apache.log4j.PropertyConfigurator.configure(Ljava/io/InputStream;)V
        	at com.liferay.calendar.portlet.CalendarPortlet.render(CalendarPortlet.java:258)
        	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:1240)
        

      PROPOSED:
      Ship Portal with the appropriate version of log4j-extras.

      QA/Solution Notes
      In 6.2, all deployed portlets have to be re-deployed so the deployer can pick-up and include the new log4j-extras.jar in the unpacked webapps in their lib folder.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abel.yu Abel Yu (Inactive)
                Reporter:
                csaba.botos Csaba Botos (Inactive)
                Participants of an Issue:
                Recent user:
                Csaba Turcsan
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

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

                  Packages

                  Version Package
                  7.0.0 DXP FP39
                  7.0.0 DXP SP7
                  7.0.5 CE GA6
                  7.0.X
                  7.1.0 M1
                  7.1.X
                  Master