ICEfaces
  1. ICEfaces
  2. ICE-9213

Resource Coalescing attempts to process empty resources resulting in NPE

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.3
    • Fix Version/s: EE-3.3.0.GA, 4.0.BETA, 4.0
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      n/a
    • Assignee Priority:
      P1

      Description

      Turning on Resource Coalescing in ICEmobile JSF Showcase results in the following exception:

      java.lang.NullPointerException
              at org.icefaces.impl.application.CoalescingResourceHandler.createResource(CoalescingResourceHandler.java:56)
              at org.icefaces.impl.application.CoalescingResourceHandler.createResource(CoalescingResourceHandler.java:75)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at org.icefaces.impl.component.NavigationNotifierHandler.createResource(NavigationNotifierHandler.java:51)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at javax.faces.application.ResourceHandlerWrapper.createResource(ResourceHandlerWrapper.java:96)
              at org.icefaces.impl.application.CoalescingResourceHandler$ResourceCollector.replaceResources(CoalescingResourceHandler.java:119)
              at org.icefaces.impl.application.CoalescingResourceHandler$ResourceCollector.processEvent(CoalescingResourceHandler.java:86)
              at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
              at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2163)
              at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:2139)
              at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:303)
              at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
              at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:818)
              at javax.faces.component.UIViewRoot.encodeBegin(UIViewRoot.java:954)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1777)
              at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
              at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
              at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
              at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
              at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:662)

      Debugging this shows that both resourceName and resourceLibrary variables are null in CoalescingResourceHandler.createResource()

        Issue Links

          Activity

          Hide
          Philip Breau added a comment - - edited

          Following diff corrects the issue:

          Index: C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java
          ===================================================================
          --- C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java	(revision 34508)
          +++ C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java	(working copy)
          @@ -51,19 +51,22 @@
           
               public Resource createResource(String resourceName, String libraryName, String contentType) {
                   FacesContext context = FacesContext.getCurrentInstance();
          -        if (EnvUtils.isCoallesceResources(context)) {
          -            if (resourceName.equals(COALESCED + CSS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) {
          -                CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + CSS_EXTENSION);
          -                return new CoalescingResource(COALESCED + CSS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos);
          -            } else if (resourceName.equals(COALESCED + JS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) {
          -                CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + JS_EXTENSION);
          -                return new CoalescingResource(COALESCED + JS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos);
          +        if( resourceName != null ){
          +            if (EnvUtils.isCoallesceResources(context)) {
          +                if (resourceName.equals(COALESCED + CSS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) {
          +                    CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + CSS_EXTENSION);
          +                    return new CoalescingResource(COALESCED + CSS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos);
          +                } else if (resourceName.equals(COALESCED + JS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) {
          +                    CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + JS_EXTENSION);
          +                    return new CoalescingResource(COALESCED + JS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos);
          +                } else {
          +                    return super.createResource(resourceName, libraryName, contentType);
          +                }
                       } else {
                           return super.createResource(resourceName, libraryName, contentType);
                       }
          -        } else {
          -            return super.createResource(resourceName, libraryName, contentType);
                   }
          +        return null;
               }
           
               public Resource createResource(String resourceName) {
          @@ -112,19 +115,21 @@
                           String nextLibrary = (String) nextAttributes.get("library");
                           String iceType = (String) nextAttributes.get("ice.type");
                           Resource nextResource = null;
          -                if(iceType == null) {
          -                    nextResource = resourceHandler.createResource(nextName, nextLibrary);
          -                }
          -                if (nextName.endsWith(extension) && !"jsf.js".equals(nextName) &&
          -                        nextResource != null && !URI.create(nextResource.getRequestPath()).isAbsolute()) {
          -                    CoalescingResource.Info info = new CoalescingResource.Info(nextName, nextLibrary);
          -
          -                    if (!context.isPostback() || previousResourceInfos.resources.contains(info)) {
          -                        resourceInfos.resources.add(info);
          -                    } else {
          -                        toBeReAdded.add(next);
          +                if( nextName != null ){
          +                    if(iceType == null) {
          +                        nextResource = resourceHandler.createResource(nextName, nextLibrary);
                               }
          -                    root.removeComponentResource(context, next);
          +                    if (nextName.endsWith(extension) && !"jsf.js".equals(nextName) &&
          +                            nextResource != null && !URI.create(nextResource.getRequestPath()).isAbsolute()) {
          +                        CoalescingResource.Info info = new CoalescingResource.Info(nextName, nextLibrary);
          +    
          +                        if (!context.isPostback() || previousResourceInfos.resources.contains(info)) {
          +                            resourceInfos.resources.add(info);
          +                        } else {
          +                            toBeReAdded.add(next);
          +                        }
          +                        root.removeComponentResource(context, next);
          +                    }
                           }
                       }
          
          Show
          Philip Breau added a comment - - edited Following diff corrects the issue: Index: C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java =================================================================== --- C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java (revision 34508) +++ C:/work/projects/icefaces3/icefaces/core/src/main/java/org/icefaces/impl/application/CoalescingResourceHandler.java (working copy) @@ -51,19 +51,22 @@ public Resource createResource( String resourceName, String libraryName, String contentType) { FacesContext context = FacesContext.getCurrentInstance(); - if (EnvUtils.isCoallesceResources(context)) { - if (resourceName.equals(COALESCED + CSS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) { - CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + CSS_EXTENSION); - return new CoalescingResource(COALESCED + CSS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos); - } else if (resourceName.equals(COALESCED + JS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) { - CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + JS_EXTENSION); - return new CoalescingResource(COALESCED + JS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos); + if ( resourceName != null ){ + if (EnvUtils.isCoallesceResources(context)) { + if (resourceName.equals(COALESCED + CSS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) { + CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + CSS_EXTENSION); + return new CoalescingResource(COALESCED + CSS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos); + } else if (resourceName.equals(COALESCED + JS_EXTENSION) && libraryName.equals(ICE_CORE_LIBRARY)) { + CoalescingResource.Infos resourceInfos = (CoalescingResource.Infos) context.getExternalContext().getSessionMap().get(CoalescingResourceHandler.class.getName() + JS_EXTENSION); + return new CoalescingResource(COALESCED + JS_EXTENSION, ICE_CORE_LIBRARY, getMapping(context), isExtensionMapping(context), resourceInfos); + } else { + return super .createResource(resourceName, libraryName, contentType); + } } else { return super .createResource(resourceName, libraryName, contentType); } - } else { - return super .createResource(resourceName, libraryName, contentType); } + return null ; } public Resource createResource( String resourceName) { @@ -112,19 +115,21 @@ String nextLibrary = ( String ) nextAttributes.get( "library" ); String iceType = ( String ) nextAttributes.get( "ice.type" ); Resource nextResource = null ; - if (iceType == null ) { - nextResource = resourceHandler.createResource(nextName, nextLibrary); - } - if (nextName.endsWith(extension) && ! "jsf.js" .equals(nextName) && - nextResource != null && !URI.create(nextResource.getRequestPath()).isAbsolute()) { - CoalescingResource.Info info = new CoalescingResource.Info(nextName, nextLibrary); - - if (!context.isPostback() || previousResourceInfos.resources.contains(info)) { - resourceInfos.resources.add(info); - } else { - toBeReAdded.add(next); + if ( nextName != null ){ + if (iceType == null ) { + nextResource = resourceHandler.createResource(nextName, nextLibrary); } - root.removeComponentResource(context, next); + if (nextName.endsWith(extension) && ! "jsf.js" .equals(nextName) && + nextResource != null && !URI.create(nextResource.getRequestPath()).isAbsolute()) { + CoalescingResource.Info info = new CoalescingResource.Info(nextName, nextLibrary); + + if (!context.isPostback() || previousResourceInfos.resources.contains(info)) { + resourceInfos.resources.add(info); + } else { + toBeReAdded.add(next); + } + root.removeComponentResource(context, next); + } } }
          Hide
          Mircea Toma added a comment -

          Avoid coalescing resources that do not have "name" attribute set since they cannot be identified and ordered. Reverse String.equals test to check the constant against the parameters (that could be null).

          Show
          Mircea Toma added a comment - Avoid coalescing resources that do not have "name" attribute set since they cannot be identified and ordered. Reverse String.equals test to check the constant against the parameters (that could be null).

            People

            • Assignee:
              Mircea Toma
              Reporter:
              Philip Breau
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: