Letractively / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

SpringWroFilter will not work without abusing or changing WroFilter API #804

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I get a null pointer exception. By the time of access I can see that the 
factory field is set in SpringWroFilter, but not the wroManagerFactory in the 
base class WroFilter.

11:11:44.426 WEB [] DEBUG ro.isdc.wro.http.WroFilter - Exception occured
java.lang.NullPointerException: The validated object is null
at org.apache.commons.lang3.Validate.notNull(Validate.java:222) 
~[commons-lang3-3.1.jar:3.1]
at org.apache.commons.lang3.Validate.notNull(Validate.java:203) 
~[commons-lang3-3.1.jar:3.1]
at ro.isdc.wro.model.group.processor.InjectorBuilder.(InjectorBuilder.java:77) 
~[wro4j-core-1.7.1.jar:1.7.1]
at 
ro.isdc.wro.model.group.processor.InjectorBuilder.create(InjectorBuilder.java:69
) ~[wro4j-core-1.7.1.jar:1.7.1]
at ro.isdc.wro.http.WroFilter.getInjector(WroFilter.java:319) 
~[wro4j-core-1.7.1.jar:1.7.1]
at ro.isdc.wro.http.WroFilter.handledWithRequestHandler(WroFilter.java:302) 
~[wro4j-core-1.7.1.jar:1.7.1]
at ro.isdc.wro.http.WroFilter.doFilter(WroFilter.java:269) 
~[wro4j-core-1.7.1.jar:1.7.1]
at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:243) [catalina.jar:7.0.39.B]
at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:210) [catalina.jar:7.0.39.B]

Looking at the code I can see why this happens. WroFilter init() function calls 
createWroManagerFactory() and in turn call the overridden 
newWroManagerFactory(). It subsequently calls the overridden doInit() function 
-- it is only at this point that the factory field will be set. By then it is 
too late.

Given the use of the final keyword on the servlet filter init() method, I can 
see no way to resolve this in SpringWroFilter itself. A hook needs to be added 
at the beginning of the init method or else the final keyword removed, so that 
SpringWroFilter can do its job before newWroManagerFactory() is called. Since 
the API needs to change and I don't know what the preference would be, I 
haven't made a pull request for it.

Rather, I sneaked in a fix with this awful hack. newWroConfigurationFactory can 
be overridden and gets access to filterConfig before newWroManagerFactory() is 
called.

@Override
protected ObjectFactory<WroConfiguration> newWroConfigurationFactory(final 
FilterConfig filterConfig) {
    doInitABitEarlier(filterConfig);
    return super.newWroConfigurationFactory(filterConfig);
}
Grotesque -- we need an API change to WroFilter().

Original issue reported on code.google.com by alex.obj...@gmail.com on 17 Oct 2013 at 11:35

GoogleCodeExporter commented 9 years ago
Reported on github: https://github.com/alexo/wro4j/issues/155

Original comment by alex.obj...@gmail.com on 17 Oct 2013 at 11:35

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 5 Nov 2013 at 1:56

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 8 Jan 2014 at 3:11