MissingPropertyException when extending HttpServletRequestWrapper
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Download [TestGrails3App-bug-report-08022019.zip](https://github.com/grails/grails-core/files/2845257/TestGrails3App-bug-report-08022019.zip)
2. `run-app`
3. set debug Breakpoint at `de.testapp.servletfilter.MyServletFilter#doFilter` line 16
4. call http://localhost:8080/foo
### Expected Behaviour
I have defined a ServletFilter ([javax.servlet.Filter](https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/Filter.html)) which is defined in `resources.groovy`. In the `doFilter()` method I use the groovy DSL to set an attribute to the request object (`HttpServletRequest`):
`httpReq.filter3 = "filter3-value"`
This doesn't cause any problems. Then I use the request object to create a `de.testapp.servletfilter.MyServletFilter.CleanServletRequest` object which extends the `HttpServletRequestWrapper`. This class does nothing but extending its super class. After that I want to set another attribute to the request but this time I use the `cleanRequest` object since this will be the one I'm going to feed the filter chain with for further processing:
`cleanRequest.setAttribute("filter1", "filter1-value")`
No problems when using the setter `setAttribute()`. When I want to do this using groovy DSL though an `groovy.lang.MissingPropertyException` gets thrown:
`cleanRequest.filter2 = "filter2-value" // throws exception!`
**Please note: This used to work in Grails 2.5.6.**
I use this servlet filter to create a derived HttpServletRequestWrapper just like in my example. By overriding the `getParameter()` method I can process the parameters before handing them to the application layer.
### Actual Behaviour
```
2019-02-08 14:31:23.432 ERROR --- [nio-8080-exec-9] .a.c.c.C.[.[.[.[grailsDispatcherServlet] : Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception
groovy.lang.MissingPropertyException: No such property: filter2 for class: de.testapp.servletfilter.MyServletFilter
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1014)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2749)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3785)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:215)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:497)
at de.testapp.servletfilter.MyServletFilter$CleanServletRequest.propertyMissing(MyServletFilter.groovy)
at sun.reflect.GeneratedMethodAccessor255.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1427)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:894)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2751)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3785)
at de.testapp.servletfilter.MyServletFilter$CleanServletRequest.setProperty(MyServletFilter.groovy)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:213)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:497)
at de.testapp.servletfilter.MyServletFilter.doFilter(MyServletFilter.groovy:20)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
```
### Environment Information
- **Operating System**: any, in my case Windows 10 1809
- **Grails Version:** 3.3.9
- **JDK Version:** `jdk8u202-b08-adoptopenjdk`
### Example Application
[TestGrails3App-bug-report-08022019.zip](https://github.com/grails/grails-core/files/2845257/TestGrails3App-bug-report-08022019.zip)
Contributor guide
Research direction
Start with the linked example application and MyServletFilter.groovy, especially doFilter and the CleanServletRequest wrapper shown in the stack trace. Reproduce the difference between direct setAttribute() and Groovy property assignment on HttpServletRequestWrapper under Grails 3.3.9, then compare with the reported Grails 2.5.6 behavior. Done means the wrapper accepts the property assignment without MissingPropertyException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100