在对象上接收空引用

时间:2014-01-10 21:44:39

标签: grails groovy

我在处理服务方面遇到了一些令人沮丧的问题。正如标题所述,当用作参数时,我在对象上得到一个空引用错误。当我使用步进功能检查intelliJ时,会有一个对象传递给每个服务/函数正确的值。我错过了什么吗?

查看:

<g:canAddSupervisor performanceReview="${performanceReview}">
    do stuff...
</g:canAddSupervisor>

GateTagLib.groovy

class GateTagLib {

    def canAddSupervisor = { attrs, body ->

        Person viewer = springSecurityService.currentUser as Person
        PerformanceReview review = attrs["performanceReview"]

        if (performanceReviewShowGateService.canShowAddSupervisorButton(viewer, review)) {
            out << body()
        }
    }
 }

PerformanceReviewShowGateService.groovy

class PerformanceReviewShowGateService {
    def performanceReviewStatusGateService

    boolean canShowAddSupervisorButton(Person viewer, PerformanceReview review) {
        if (!performanceReviewStatusGateService.isStatusFinalizedOrComplete(review) && isViewerAdminOrHR(viewer)) {
            true
        } else {
            false
        }
    }

PerformanceReviewStatusGateService.groovy

boolean isStatusFinalizedOrComplete(PerformanceReview review) {
    def statusName = review.performanceReviewStatus.name
    (statusName == "Finalized" || statusName == "Complete")
}

Stacktrace:

2014-01-10 15:19:58,018 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /PerformanceEvaluations/performanceReview/323
    Cannot invoke method isStatusFinalizedOrComplete() on null object. Stacktrace follows:
    org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Error executing tag <g:render>: Error executing tag <g:canAddSupervisor>: Cannot invoke method isStatusFinalizedOrComplete() on null object
        at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
        at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
        at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:117)
        at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:231)
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:197)
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:171)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
    Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <g:render>: Error executing tag <g:canAddSupervisor>: Cannot invoke method isStatusFinalizedOrComplete() on null object
        at C__Users_per245_PerformanceReview_grails_app_views_performanceReview_show_gsp$_run_closure2.doCall(show.gsp:37)
        at C__Users_per245_PerformanceReview_grails_app_views_performanceReview_show_gsp.run(show.gsp:136)
        ... 9 more
    Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag <g:canAddSupervisor>: Cannot invoke method isStatusFinalizedOrComplete() on null object
        at C__Users_per245_PerformanceReview_grails_app_views_performanceReview__evaluationListTemplate_gsp.run(_evaluationListTemplate.gsp:184)
        ... 11 more
    Caused by: java.lang.NullPointerException: Cannot invoke method isStatusFinalizedOrComplete() on null object
        at com.example.performanceevaluations.PerformanceReviewShowGateService$$EOSZwaTu.canShowAddSupervisorButton(PerformanceReviewShowGateService.groovy:71)
        at com.example.performanceevaluations.GateTagLib$_closure6$$EOSZwaUW.doCall(GateTagLib.groovy:68)
        ... 12 more

0 个答案:

没有答案