<cfthread> </cfthread>上的空指针异常

时间:2013-12-17 03:06:31

标签: coldfusion railo cfml application.cfc fw1

以下代码适用于Adobe ColdFusion 9.01+,但不适用于Railo 4.1

此外,这只会在Post

上失败

此代码在setupRequest()

中的FW / 1 application.cfc内调用
<cfthread name="threadA" action="run"> 

<cftry>

<cfquery>
    INSERT
    INTO    dbo.Traffic (Circuit, Fuseaction, IP_hash)
    VALUES  (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listfirst(variables.rc.fuseaction, '.')#">,
        <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listlast(variables.rc.fuseaction, '.')#">,
        <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#cgi.remote_addr#">
        )
</cfquery>


<cfcatch />
</cftry>

</cfthread>

错误

  

java.lang.NullPointerException at   railo.runtime.net.http.HttpUtil.cloneParameters(HttpUtil.java:66):66   在   railo.runtime.net.http.HttpServletRequestDummy.clone(HttpServletRequestDummy.java:677):677   在   railo.runtime.thread.ThreadUtil.cloneHttpServletRequest(ThreadUtil.java:67):67   在   railo.runtime.thread.ThreadUtil.clonePageContext(ThreadUtil.java:29):29   在   railo.runtime.thread.ChildThreadImpl(ChildThreadImpl.java:101):101   at railo.runtime.tag.ThreadTag.register(ThreadTag.java:269):269 at at   scorecard38.application_cfc $ cf.udfCall(d:\ railo \ web应用\ WWW \ Scorecard38 \的Application.cfc:162):162   at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:94):94

狂野猜测

variables.rc未被复制到帖子中

2 个答案:

答案 0 :(得分:1)

除非您将其添加为参数,否则不会将

variables.rc复制到线程中。添加rc作为参数,然后代替variables.rc,您将通过arguments.rc

访问它
<cfthread name="threadA" action="run" rc="#variables.rc#">
  <cftry>

    <cfquery>
    INSERT INTO dbo.Traffic (Circuit, Fuseaction, IP_hash)
    VALUES  (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listfirst(arguments.rc.fuseaction, '.')#">,
    <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listlast(arguments.rc.fuseaction, '.')#">,
    <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#cgi.remote_addr#">
    )
    </cfquery>

    <cfcatch />
  </cftry>

</cfthread>

如果这不起作用,您必须删除try / catch并转出cfthread以查看错误。下面的代码将输出'Variable C is undefined'

<cfthread name="threadA" action="run">
  <cfset b = c>
</cfthread>
<cfdump var="#cfthread#"><cfabort>

答案 1 :(得分:1)

我遇到了同样的问题。您正在使用CGI变量以及导致问题的原因