Bug 42866

Summary: Using a function via EL produces ClassNotFoundException
Product: Tomcat 6 Reporter: Denny Strietzbaum <denny.strietzbaum>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal CC: david.green, karl.toffel
Priority: P3    
Version: unspecified   
Target Milestone: default   
Hardware: PC   
OS: Windows XP   

Description Denny Strietzbaum 2007-07-12 01:23:35 UTC
running on tomcat 6.0.13, using myfaces 1.2 (snapshot) and facelets 1.1.13

When using a user defined function via EL, the classloader fails.
(Function was correct defined within a functionlib ... i skip this as it involves Facelets)
This problem first occurs when using the current myfaces 1.2 implementation.
As myfaces 1.1x bring their own el-implementation, myfaces 1.2x rely on the jsp container
(as defined by the jsf 1.1 and 1.2 spec)

Looking at org.apache.el.lang.FunctionMapperImpl$Function.getMethod(FunctionMapperImpl.java:147)
i replaced
Class t = Class.forName(this.owner);
with
Class t = Class.forName(this.owner, true, Thread.currentThread().getContextClassLoader());
and all works fine.

Below the stacktrace:

java.lang.ClassNotFoundException: mypackage.faces.util.ELFunctions
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.apache.el.lang.FunctionMapperImpl$Function.getMethod(FunctionMapperImpl.java:147)
        at org.apache.el.lang.FunctionMapperImpl.resolveFunction(FunctionMapperImpl.java:53)
        at org.apache.el.parser.AstFunction.getValue(AstFunction.java:71)
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
        at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:41)
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
        at javax.faces.component.UIOutput.getValue(UIOutput.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.facelets.util.DevTools.writeAttributes(DevTools.java:240)
        at com.sun.facelets.util.DevTools.writeStart(DevTools.java:284)
        at com.sun.facelets.util.DevTools.writeComponent(DevTools.java:189)
        at com.sun.facelets.util.DevTools.writeComponent(DevTools.java:207)
        at com.sun.facelets.util.DevTools.debugHtml(DevTools.java:107)
        at com.sun.facelets.FaceletViewHandler.handleRenderException(FaceletViewHandler.java:677)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:645)
        at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at de.hybris.platform.util.RootRequestFilter.doFilter(RootRequestFilter.java:525)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
Comment 1 Jaroslav Abraham 2007-10-18 06:47:38 UTC
I have obviously the same problem on Tomcat 6.0.14, Sun JSF RI 1.2_05. It works
when the state saving method is set to 'server', but with 'client' method it
fails after deserialization exactly like the original comment says. The tomcat
classloader used for EL has no access to the webapp class, where is the function
implemented.
Comment 2 David Green 2007-11-28 13:20:58 UTC
I am experiencing the same problem.  The original description is accurate in that it appears to be a 
classloader problem.  This problem only appears in the restore view phase when deserialization occurs, 
since this is the only time when the Function.m member can be null.  The web application class loader is 
the current thread context class loader, so the suggested change works well.
Comment 3 David Green 2007-11-28 13:22:54 UTC
BTW, this bug makes user-defined EL functions unusable unless the web app can bundle its own el 
implementation.  I haven't been able to get that to work on Tomcat 6.0.14.  I suggest that the priority of 
this fix gets raised.
Comment 4 David Green 2007-11-28 13:31:40 UTC
I've managed to workaround this issue by including the jasper-el.jar from the Tomcat distribution in the 
war file.
Comment 5 Tuomas Kiviaho 2008-01-25 02:34:41 UTC
Isn't this a duplicate of <http://issues.apache.org/bugzilla/show_bug.cgi?id=41797>
Comment 6 Grant Currey 2008-01-28 13:50:39 UTC
This is indeed a duplicate of the mentioned bug
http://issues.apache.org/bugzilla/show_bug.cgi?id=41797

Looks like a patch has been added to tomcat, but it is not part of the latest
6.0.14 release.

The workaround of adding jasper-el.jar directly into the WAR of your application
appears to work.  You can get this from your the tomcat lib folder.
Comment 7 Mark Thomas 2008-01-28 14:06:47 UTC

*** This bug has been marked as a duplicate of 41797 ***