Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3192] HTTPClient crashes with java.lang.NullPointerException for 0 length responses

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-04-26T09:13:25.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-11
ComponentsAndroid
Labelsandroid, defect, reported-1.5.1
ReporterDaniel Cameron
AssigneeDon Thorp
Created2011-04-15T03:39:08.000+0000
Updated2011-04-26T09:13:25.000+0000

Description

HTTPClient crashes when the HTTP Response sent is 0 bytes long.

Versions:

  • Titanium Mobile SDK 1.5.1
  • Android SDK r9

Debugging Trace:

[TRACE] D/TiHttpClient( 1727): (kroll$1) [96,2260] Setting ready state to 1
[TRACE] W/TiTabActivity( 1727): (main) [94,2354] Notifying TiTabGroup, activity is created
[TRACE] D/qemud ( 38): fdhandler_accept_event: accepting on fd 10
[TRACE] D/qemud ( 38): created client 0x2c938 listening on fd 15
[TRACE] D/qemud ( 38): client_fd_receive: attempting registration for service 'sensors'
[TRACE] D/qemud ( 38): client_fd_receive: -> received channel id 20
[TRACE] D/qemud ( 38): client_registration: registration succeeded for client 20
[TRACE] D/qemud ( 38): fdhandler_event: disconnect on fd 15
[TRACE] I/ActivityManager( 60): Displayed activity unittest.httpclient/ti.modules.titanium.ui.TiTabActivity: 2466 ms (total 2466 ms)
[TRACE] D/dalvikvm( 1727): GC_FOR_MALLOC freed 3458 objects / 210168 bytes in 150ms
[TRACE] D/TiHttpClient( 1727): (TiHttpClient-1) [4134,6488] Setting ready state to 2
[TRACE] D/TiHttpClient( 1727): (TiHttpClient-1) [2,6490] Setting ready state to 3
[TRACE] E/TiHttpClient( 1727): (TiHttpClient-1) [10,6500] HTTP Error (java.lang.NullPointerException): java.lang.NullPointerException
[TRACE] E/TiHttpClient( 1727): java.lang.NullPointerException
[TRACE] E/TiHttpClient( 1727): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.finishedReceivingEntityData(TiHTTPClient.java:316)
[TRACE] E/TiHttpClient( 1727): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:252)
[TRACE] E/TiHttpClient( 1727): at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:165)
[TRACE] E/TiHttpClient( 1727): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
[TRACE] E/TiHttpClient( 1727): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
[TRACE] E/TiHttpClient( 1727): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:997)
[TRACE] E/TiHttpClient( 1727): at java.lang.Thread.run(Thread.java:1096)
[TRACE] I/TiHttpClient( 1727): (TiHttpClient-1) [28,6528] Sending error java.lang.NullPointerException
[TRACE] W/TiConvert( 1727): (kroll$1) [28,6556] Unsupported type class ti.modules.titanium.network.HTTPClientProxy
[ERROR] [3,6559] HTTPClient error={"error":"java.lang.NullPointerException"}

Repo steps:

  • Create New Project
  • Add the following to app.js:
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function (e) {
    Ti.API.error('HTTPClient error='+JSON.stringify(e));
};
xhr.onload = function () {
    Ti.API.info('status=' + xhr.status);
    Ti.API.info('responseText=' + xhr.responseText);
    Ti.API.info('responseText=' + xhr.responseText);
};
xhr.open('GET', 'http://www.danielcameron.com/m/empty.html'); // can replace with any HTTP request for a 0 byte file
xhr.send();

Comments

  1. Daniel Cameron 2011-04-15

    Titanium also crashes when sending null post parameters:
    xhr.send({ somearg: 'ok', thisCrashesApp: null });

       [TRACE] D/TiHttpClient( 511): (kroll$1) [53,1686] Setting ready state to 1
       [TRACE] E/KrollMethod( 511): (kroll$1) [18,1704] Exception calling kroll method send, invocation: null ]
       [TRACE] E/KrollMethod( 511): java.lang.NullPointerException
       [TRACE] E/KrollMethod( 511): at ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:861)
       [TRACE] E/KrollMethod( 511): at ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:88)
       [TRACE] E/KrollMethod( 511): at ti.modules.titanium.network.HTTPClientProxyBindingGen$17.invoke(HTTPClientProxyBindingGen.java:584)
       [TRACE] E/KrollMethod( 511): at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:48)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1711)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
       [TRACE] E/KrollMethod( 511): at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
       [TRACE] E/KrollMethod( 511): at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:195)
       [TRACE] E/KrollMethod( 511): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:220)
       [TRACE] E/KrollMethod( 511): at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:115)
       [TRACE] E/KrollMethod( 511): at android.os.Handler.dispatchMessage(Handler.java:95)
       [TRACE] E/KrollMethod( 511): at android.os.Looper.loop(Looper.java:123)
       [TRACE] E/KrollMethod( 511): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:73)
       [TRACE] W/TiTabActivity( 511): (main) [96,1800] Notifying TiTabGroup, activity is created
       [TRACE] E/KrollContext( 511): (kroll$1) [2,1802] Error evaluating source: Wrapped java.lang.NullPointerException (app://app.js#77)
       [TRACE] E/KrollContext( 511): org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (app://app.js#77)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1781)
       [TRACE] E/KrollContext( 511): at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:85)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1711)
       [TRACE] E/KrollContext( 511): at script(app://app.js:77)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
       [TRACE] E/KrollContext( 511): at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
       [TRACE] E/KrollContext( 511): at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:195)
       [TRACE] E/KrollContext( 511): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:220)
       [TRACE] E/KrollContext( 511): at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:115)
       [TRACE] E/KrollContext( 511): at android.os.Handler.dispatchMessage(Handler.java:95)
       [TRACE] E/KrollContext( 511): at android.os.Looper.loop(Looper.java:123)
       [TRACE] E/KrollContext( 511): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:73)
       [TRACE] E/KrollContext( 511): Caused by: java.lang.NullPointerException
       [TRACE] E/KrollContext( 511): at ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:861)
       [TRACE] E/KrollContext( 511): at ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:88)
       [TRACE] E/KrollContext( 511): at ti.modules.titanium.network.HTTPClientProxyBindingGen$17.invoke(HTTPClientProxyBindingGen.java:584)
       [TRACE] E/KrollContext( 511): at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:48)
       [TRACE] E/KrollContext( 511): ... 13 more
       [TRACE] E/TiContext( 511): (kroll$1) [49,1851] Rhino Error: app://app.js:77,0
       [TRACE] E/TiContext( 511): (kroll$1) [3,1854] Message: Wrapped java.lang.NullPointerException (app://app.js#77)
       [TRACE] E/TiContext( 511): (kroll$1) [1,1855] Source: null
       
  2. Daniel Cameron 2011-04-15

    Assigning to hopefully the correct person.

  3. Opie Cyrus 2011-04-15

    Created, new ticket #3358 for the issue regarding send with a null value.

    In regards to the original issue, I am unable to reproduce on latest build on master. Is someone else able to confirm that this is still an issue on the latest build?

  4. Daniel Cameron 2011-04-15

    Titanium Mobile SDK 1.6.1
    Android SDK r10
    Retested with above versions with an APIs 2.2 emulator and no longer crashing. Looks like it got fixed somewhere between 1.5.1 and 1.6.1.

JSON Source