{ "id": "120234", "key": "TIMOB-15336", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "15699", "description": "2013 Sprint 21", "name": "2013 Sprint 21", "archived": true, "released": true, "releaseDate": "2013-10-18" }, { "id": "15700", "description": "2013 Sprint 21 API", "name": "2013 Sprint 21 API", "archived": true, "released": true, "releaseDate": "2013-10-18" }, { "id": "14982", "description": "Release 3.2.0", "name": "Release 3.2.0", "archived": false, "released": true, "releaseDate": "2013-12-19" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-10-10T22:24:00.000+0000", "created": "2013-09-19T22:29:33.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "triage" ], "versions": [], "issuelinks": [], "assignee": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "updated": "2013-10-21T23:11:03.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "Included is a sample app which demonstrates this bug; it seems like running blur on a text view right before it get removed from its parent view causes this crash reliably (the buggy section noted with a XXX comment).\r\n\r\nDigging into it more, it seems like a general race issue; underlying this is blur uses TiMessenger#postOnMain, which uses Message#sendToTarget underneath, whereas TiUIView#remove uses TiMessenger#sendBlockingMessage, which if another sendBlockingMessage was already running, will be ran before that sendBlockingMessage finishes, and more notably before the blur message is processed.", "attachment": [ { "id": "42638", "filename": "ReproApp.tgz", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-19T23:25:33.000+0000", "size": 34702, "mimeType": "application/x-gzip" } ], "flagged": false, "summary": "Android TiViewProxy crashes with NullPointerException with blur()", "creator": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Titanium SDK 3.1.2, 3.1.3", "comment": { "comments": [ { "id": "272052", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "For reference, the entirety of app.js below:\r\n==============================================\r\n\r\n{code:javascript}\r\nvar textField = Ti.UI.createTextField({\r\n\tborderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,\r\n\tcolor: '#336699',\r\n\ttop: 40, width: 400\r\n});\r\n\r\nvar button = Ti.UI.createButton({ title: 'Remove' });\r\nbutton.addEventListener('click', function() {\r\n\t// XXX: issue here\r\n\ttextField.blur();\r\n\tview.remove(textField);\r\n});\r\n\r\nvar view = Ti.UI.createView();\r\nview.add(textField);\r\nview.add(button);\r\n\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor:'#ffffff',\r\n\tnavBarHidden:true,\r\n\texitOnClose:true\r\n});\r\nwin.add(view);\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-19T23:22:49.000+0000", "updated": "2013-09-20T18:16:52.000+0000" }, { "id": "272079", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Below are the two calls that occur in direct succession to each other, which causes a null pointer exception. It also shows the stack trace necessary to understand why this null pointer exception occurs; the underlying issue has nothing to do with textfield or blurring specifically, but rather an inconsistency with how Android's Handler, Message and Titanium's TiMessenger classes work with each other in message handling.\r\n\r\n\r\n* textfield.blur()\r\n*# Inherited from TiViewProxy, so calls TiViewProxy#blur.\r\n*# Is being called from runtime thread, so sends to main handler with msg MSG_FOCUS (async call).\r\n*# Handled by TiViewProxy#handleMessage, calls TiViewProxy#handleBlur, which calls TiUIView#blur.\r\n*# Within it calls TiMessenger#postOnMain (with a runnable referencing TiUIView#nativeView private field), which just tells the main handler to run the runnable later on (another async call).\r\n*# Once the runnable is run, nativeView is already null, thus causing a NullPointerException due to trying to dot reference it.\r\n\r\n* view.remove(textfield)\r\n*# Remove is mapped to TiViewProxy#remove, which calls TiMessenger#sendBlockingMainMessage with msg MSG_REMOVE_CHILD because it is being called from runtime thread (and child view textfild as arg).\r\n*# Within here it delegates to the current threadlocal's TiMessenger instance (so runtime thread instance) to the instance call TiMessenger#sendBlockingMessage with the main messenger passed in as an argument.\r\n*# Within this method call (targetMessenger#sendMessage) the targetMessegner is the main thread's ti messenger with a message whose obj is set to an aysnc result (which contains the textfield as arg to async result).\r\n*# In sendMessage, we note that the current thread's id and the main messenger's thread id is different (runtime vs main UI thread), so we either directly do message#sendToTarget if its not blocking (which is when no blocking message is currently running), or if it is blocking, just put in onto the queue to be processed later.\r\n*# The bug occurs when it is blocking and placed on the queue, because that means another blocking message is currently running. This logic is located within the anonymous subclass of AsyncResult defined in TiMessenger#sendMessage, specifically getResult. In there it calls dispatchMessage when the blocking message isn't done responding yet, which *synchronously* processes all queued messages, including MSG_REMOVE_CHILD.\r\n*# From there it is easy to see that MSG_REMOVE_CHILD leads to calling the textfield's releaseViews method, which nullifies the underlying nativeView field. Also, at this point we are still technically still completing a message previous to the text view's MSG_FOCUS above, as that is queued within the main handler's internal queue.\r\n\r\nFrom following the traces above, it goes without saying that this issue, while only concretely shown with text text blurring, can occur anywhere within Ti code when using TiMessenger#sendBlockingMainMessage after TiMessenger#postOnMain while expecting TiMessenger#postOnMain method to complete first.", "updateAuthor": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-20T06:14:23.000+0000", "updated": "2013-09-20T17:23:32.000+0000" }, { "id": "272393", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hi Steven Lee,\r\n\r\nI have tested your code you just create a view and add this a textfield and remove this through the button event listener and it occurs. So you say what is the expected behavior and actual behavior. And do you know actually why blur() method is used if you know this clearly, please write this. \r\n\r\nThanks ", "updateAuthor": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2013-09-22T17:54:04.000+0000", "updated": "2013-09-22T18:00:34.000+0000" }, { "id": "272403", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi Motiur,\n\nThe reason why we were originally blurring the text view was to remove the keyboard view in Android when we switched views (so our own original code we were removing the whole parent view rather than just the text field), but since then for that particular issue we have sidestepped past the issue with just using Ti.UI.Android.hideSoftKeyboard method call instead.\n\nThat being said, the *real issue* I am reporting on is what is causing blur to fail to begin with, because it shouldn't ever in this circumstance. And what the root issue is I have documented clearly in my second comment; *there is an inherent race issue that happens when using TiMessenger#postOnMain versus TiMessenger#sendBlockingMainMessage*. Please focus on that rather than the blurring issue; this low level issue is prevalent since most async calls go through TiMessenger. The blur code is just an example of this larger issue at hand.\n\nBTW, I found an even shorter app.js that reproduces this; just look at the error logs to see the null pointer exception stack trace:\n\n{code:javascript}\nvar textField = Ti.UI.createTextField();\nvar win = Ti.UI.createWindow();\nwin.add(textField);\nwin.open();\ntextField.blur();\nwin.remove(textField);\n{code}", "updateAuthor": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-22T22:19:35.000+0000", "updated": "2013-09-22T22:19:35.000+0000" }, { "id": "272431", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hi Steven Lee,\r\nTest that code and know me is that the problem createing yet or not. \r\n\r\nArrange that code like this and test the issue. \r\n{code}\r\nvar win = Ti.UI.createWindow();\r\nvar textField = Ti.UI.createTextField();\r\ntextField.blur();\r\nwin.add(textField);\r\nwin.remove(textField);\r\nwin.open();\r\n{code}\r\n\r\nHere your first code something change here....\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor : '#ffffff',\r\n\tnavBarHidden : true,\r\n\texitOnClose : true\r\n});\r\n\r\nvar view = Ti.UI.createView({\r\n\tlayout : \"vertical\",\r\n});\r\n\r\nvar textField = Ti.UI.createTextField({\r\n\tborderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,\r\n\tcolor : '#336699',\r\n\ttop : 10,\r\n\twidth : 400\r\n});\r\nview.add(textField);\r\nvar button = Ti.UI.createButton({\r\n\ttop : 10,\r\n\ttitle : 'Blur'\r\n});\r\nbutton.addEventListener('click', function() {\r\n\r\n\t// XXX: issue here\r\n\ttextField.blur();\r\n\t//view.remove(textField);\r\n});\r\n\r\nvar button1 = Ti.UI.createButton({\r\n\ttop : 10,\r\n\ttitle : 'Remove'\r\n});\r\nbutton1.addEventListener('click', function() {\r\n\r\n\t// XXX: issue here\r\n\t//textField.blur();\r\n\tview.remove(textField);\r\n});\r\n\r\nview.add(button);\r\n\r\nview.add(button1);\r\n\r\nwin.add(view);\r\nwin.open();\r\n\r\n{code}\r\n\r\nThanks", "updateAuthor": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2013-09-23T08:01:34.000+0000", "updated": "2013-09-23T08:05:01.000+0000" }, { "id": "272435", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hi Steven Lee,\r\n \r\nDo you want to say when blur() method and remove() method are in the same button eventListner the NullPointerException is occurred? If you want to remove a textfield so it need not to blur simple. \r\n\r\nThanks ", "updateAuthor": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2013-09-23T08:23:15.000+0000", "updated": "2013-09-23T11:39:29.000+0000" }, { "id": "272487", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Like I said before, while we can avoid using those two calls together, *it is still your guy's bug that these two calls cannot be used next to each other, and potentially more location given what the root cause is*. I strongly advise you to please escalate this to a developer's attention, as you are failing to see the bigger issue due to this bug's title.", "updateAuthor": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-23T16:11:39.000+0000", "updated": "2013-09-23T16:11:39.000+0000" }, { "id": "272764", "author": { "name": "nirman99@gmail.com", "key": "nirman99@gmail.com", "displayName": "Sachitra Malwatte", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi,\nI experienced this bug too. I used blur() and remove() when i wanted to switch views and hide keyboard. It worked in 3.0.0 and earlier versions. When I switched to 3.1.3 this issue appeared. Solved by using hideSoftKeyboard method instead. But anyway this is BUG and I think it need to be fixed.\nThanks", "updateAuthor": { "name": "nirman99@gmail.com", "key": "nirman99@gmail.com", "displayName": "Sachitra Malwatte", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-25T04:09:49.000+0000", "updated": "2013-09-25T04:09:49.000+0000" }, { "id": "272816", "author": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Now that this bug has been reassigned, can the status of the bug be reopened? Thanks.", "updateAuthor": { "name": "stevenjlee", "key": "stevenjlee", "displayName": "Steven Lee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-09-25T07:39:15.000+0000", "updated": "2013-09-25T07:39:15.000+0000" }, { "id": "274146", "author": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "body": "PR : https://github.com/appcelerator/titanium_mobile/pull/4767", "updateAuthor": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-10-08T10:54:14.000+0000", "updated": "2013-10-08T10:54:14.000+0000" }, { "id": "274932", "author": { "name": "ygoldfeld", "key": "ygoldfeld", "displayName": "Yuri Goldfeld", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I have been watching this ticket and must say the above is not a solution for the underlying problem. It is not even really a solution for the MANIFESTATION of the problem. Sure, it eliminates the NullPointerException in this particular repro case... but it also will fail to hide the software keyboard, which means instead of crashing the app, the code snippet just doesn't work instead. Steven Lee can correct me, if I'm wrong on that, but it certainly looks that way.\r\n\r\nThat's not even the biggest issue with that solution either. As Steven explained, the particular blur() repro case is a MANIFESTATION of a deep underlying bug in the way TiMessenger is used in *many* places in the code. This was added after 3.0.0 and not only added the crash in question but also potentially a multitude of other issues, since this technique is used in many places all over the code. Steven went to the trouble of explaining this in his comments on 9/19, 9/22, and 9/23.", "updateAuthor": { "name": "ygoldfeld", "key": "ygoldfeld", "displayName": "Yuri Goldfeld", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-10-14T01:58:15.000+0000", "updated": "2013-10-14T01:58:15.000+0000" }, { "id": "276043", "author": { "name": "lokeshchdhry", "key": "lokeshchdhry", "displayName": "Lokesh Choudhary", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Verified the fix & the Android TiViewProxy does not throw any null pointer exception with blur.\r\nThus closing.\r\n\r\nEnvironment:\r\nAppcel Studio : 3.2.0.201310181700\r\nTi SDK : 3.2.0.v20131021142445\r\nMac OSX : 10.8.5\r\nAlloy : 1.2.2-beta\r\nCLI - 3.2.0\r\nDevice: Samsung Galaxy S4 running android 4.2.2", "updateAuthor": { "name": "lokeshchdhry", "key": "lokeshchdhry", "displayName": "Lokesh Choudhary", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2013-10-21T22:37:39.000+0000", "updated": "2013-10-21T22:37:39.000+0000" }, { "id": "276045", "author": { "name": "ygoldfeld", "key": "ygoldfeld", "displayName": "Yuri Goldfeld", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Here is an analogy for what happened in this ticket:\r\n\r\nReporter: This car has a flaw where the electrical system is defective, and therefore starting the car makes it explode. Moreover the same defect probably affects multiple other parts of the car.\r\n\r\nAppcelerator: OK, fixed.\r\n\r\nReporter: Actually even though you've eliminated the car exploding when one tries to start it, now the car just won't start. Also you in no way addressed the underlying electrical system problem, which will adversely affect the car's operation in multiple unknown ways.\r\n\r\nAppcelerator: The car no longer explodes when starting it. Thus closing.", "updateAuthor": { "name": "ygoldfeld", "key": "ygoldfeld", "displayName": "Yuri Goldfeld", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-10-21T22:46:10.000+0000", "updated": "2013-10-21T22:46:10.000+0000" }, { "id": "276050", "author": { "name": "liamcmitchell", "key": "liamcmitchell", "displayName": "Liam Mitchell", "active": true, "timeZone": "Pacific/Auckland" }, "updateAuthor": { "name": "liamcmitchell", "key": "liamcmitchell", "displayName": "Liam Mitchell", "active": true, "timeZone": "Pacific/Auckland" }, "created": "2013-10-21T23:11:03.000+0000", "updated": "2013-10-21T23:11:03.000+0000" } ], "maxResults": 15, "total": 15, "startAt": 0 } } }