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

LinkGenerator throws NPE in async code after update to Grails 3 #10435

Closed
3 of 4 tasks
demon101 opened this issue Jan 26, 2017 · 3 comments
Closed
3 of 4 tasks

LinkGenerator throws NPE in async code after update to Grails 3 #10435

demon101 opened this issue Jan 26, 2017 · 3 comments

Comments

@demon101
Copy link
Contributor

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

Simple asynchronous code throw NPE during link generation

Domain.async.task {
...
def lk = grailsLinkGenerator.link(controller: 'view', action: 'index', params: [name:name], absolute: true)
...
}

java.lang.NullPointerException: null
at org.apache.catalina.connector.Request.getServletContext(Request.java:1618)
at org.apache.catalina.connector.Request.getContextPath(Request.java:1945)
at org.apache.catalina.connector.RequestFacade.getContextPath(RequestFacade.java:783)
at javax.servlet.http.HttpServletRequestWrapper.getContextPath(HttpServletRequestWrapper.java:189)
at javax.servlet.http.HttpServletRequestWrapper.getContextPath(HttpServletRequestWrapper.java:189)
at asset.pipeline.grails.utils.net.HttpServletRequests.getBaseUrlSansScheme(HttpServletRequests.java:139)
at asset.pipeline.grails.utils.net.HttpServletRequests.getBaseUrlWithScheme(HttpServletRequests.java:123)
at asset.pipeline.grails.utils.net.HttpServletRequests.getBaseUrlWithScheme(HttpServletRequests.java:115)
at asset.pipeline.grails.utils.net.HttpServletRequests$getBaseUrlWithScheme.callStatic(Unknown Source)
at asset.pipeline.grails.CachingLinkGenerator.makeKey(CachingLinkGenerator.groovy:52)
at org.grails.web.mapping.CachingLinkGenerator.link(CachingLinkGenerator.java:78)
at org.grails.web.mapping.DefaultLinkGenerator.link(DefaultLinkGenerator.groovy)
at grails.web.mapping.LinkGenerator$link.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

Expected Behaviour

Link should be generatied. It works in grails 2

Actual Behaviour

NPE

Environment Information

  • Grails Version: 3.1.15
  • JDK Version: 8 102
osscontributor pushed a commit to osscontributor/issue10435 that referenced this issue Jan 26, 2017
@osscontributor
Copy link
Member

See the project at https://github.com/jeffbrown/issue10435.

package demo

import grails.web.mapping.LinkGenerator

import static grails.async.Promises.waitAll

class DemoController {

    LinkGenerator grailsLinkGenerator

    def index() {
        String link = '<unknown>'
        def task = Person.async.task {
            link = grailsLinkGenerator.link(controller: 'demo', action: 'foo', params: [name: 'Jeff'])
        }

        waitAll(task)

        render "Link: ${link}"
    }

    def foo(String name) {
        render "Name: $name"
    }
}

That appears to work.

Please send a PR to that project which demonstrates the problem.

Thanks for the feedback.

@demon101
Copy link
Contributor Author

demon101 commented Jan 27, 2017

@jeffbrown I hope, problem can be solved by #10437

In my app I has something like this

package demo

import grails.web.mapping.LinkGenerator

class DemoService {

    def grailsLinkGenerator

    def test() {
        
        def task = Person.async.task {
            sleep(5000)
            def link = grailsLinkGenerator.link(controller: 'demo', action: 'foo', params: [name: 'Jeff'])
            log.error(link)
        }

        return "done"
    }
}

Preparing test app for you...

@demon101
Copy link
Contributor Author

@jeffbrown can't reproduce. I hope the bug was coused by hotswap of app during development.
Will add additional logs and will check on prod enviroment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants