Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rpdai opened this issue Oct 17, 2013 · 2 comments
Open
Assignees

Comments

@rpdai
Copy link

rpdai commented Oct 17, 2013

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(ApplicationFilterChain.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().

@ghost ghost assigned alexo Oct 17, 2013
@alexo
Copy link
Owner

alexo commented Oct 17, 2013

To speed up the fix of this issue, it would be helpful to have an unit test which proves the problem or a quick start project with the configuration which is expected to work but doesn't.

@rpdai
Copy link
Author

rpdai commented Oct 18, 2013

I notice that the unit test for SpringWroFilter is empty so I can contribute this in a pull request.

@alexo alexo modified the milestones: 1.7.5, 1.7.4 Mar 21, 2014
@alexo alexo modified the milestones: 1.7.6, 1.7.5 Apr 8, 2014
@alexo alexo modified the milestones: 1.7.7, 1.7.6 Jun 30, 2014
@alexo alexo removed this from the 1.7.7 milestone Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants