Bug 28392 - 'NotePad Mono.Data.Sqlite' sample XA 5.1 Regression
Summary: 'NotePad Mono.Data.Sqlite' sample XA 5.1 Regression
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.1
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Ben Beckley
: 28992 ()
Depends on:
Reported: 2015-03-24 18:47 UTC by Ben Beckley
Modified: 2015-04-15 07:59 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ben Beckley 2015-03-24 18:47:55 UTC
This sample is not working properly when using XA but does work when using XA stable. The app crashes when trying to add a new note, or when trying to edit a note. This has been confirmed on a Nexus 9 (5.0.1), Nexus 5 (5.0), and Asus ZenFone (4.3). Here is a gist of the error:

Reproduction steps:
- Use at least XA
- Launch the sample
- Attempt to add a note or edit existing note by tapping on it
- Observe crash to home screen

Here is a link to the sample:
Development Environment:
Comment 1 Jonathan Pryor 2015-03-24 21:46:18 UTC
I believe it's an app bug. Please investigate.

Consider this code flow:

 1. NoteEditorActivity.OnCreate() is invoked with note_id >= 0:
    This will cause us to hit an `await`:


 2. The semantics of `await` is that everything starting from the `await` on
    is thrown into a delegate, which will then be appended to the Main Loop
    for invocation "later".

 3. Through "happenstance", NoteEditorActivity.OnResume() happens "next" --
    *before* the `await` registered in OnCreate() gets a chance to execute!
    If (when) this happens, `this.note` will be null!

 4. NoteEditorActivity.OnResume() accesses this.note.Body:


BOOM, NullReferenceException, which is precisely what you're seeing:

> System.NullReferenceException: Object reference not set to an instance of an object
> at Mono.Samples.Notepad.NoteEditorActivity.OnResume () <0x00020>
> at Android.App.Activity.n_OnResume (intptr,intptr) <0x0003f>
> at (wrapper dynamic-method) object.c2579d0f-4458-4b25-8e4a-b273dbc626c0 (intptr,intptr) <0x00043>

I think this code is Bad; it implicitly assumes that the await code from OnCreate() will complete before any other instance methods are invoked, and there's no reason to believe that this will be true.

In short, Don't Do That™.
Comment 2 Peter Collins 2015-04-10 14:31:53 UTC
The sample's been updated in https://github.com/xamarin/monodroid-samples/commit/e4c2e866478f03a9ade9bb65bd6374710caab3df
Comment 3 Peter Collins 2015-04-10 14:32:57 UTC
*** Bug 28992 has been marked as a duplicate of this bug. ***
Comment 4 Ram Chandra 2015-04-15 07:57:40 UTC
I have checked this issue with latest mondroid sample and with following

Sample : commit 4b0aad8c5633f3d102446af99647b0b7a53aa4da

Windows 6.2.9200.0 (64-bit)
Xamarin Studio: 5.9 (build 427)
Installation UUID: b6495454-eed9-49ee-a97b-abf8a686d664
 Microsoft .NET 4.0.30319.34003
 GTK+ 2.24.22 (MS-Windows theme)
 GTK# 2.12.26
Xamarin.Android: 5.1.0 (Enterprise Edition)
Android SDK: D:\android-sdk\android-sdk
 Supported Android versions:
  2.3    (API level 10)
  4.0.3  (API level 15)
  4.3    (API level 18)
  4.4    (API level 19)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode)
=== Build Information ===
Release ID: 509000427
Git revision: 04666fd43a57b4782529cad9723ce1f54926fe6c
Build date: 2015-04-14 18:13:25-04
Xamarin addins: 791954691dfbc403676a103e52a0bb9754b9af29

Observation:  I have checked this sample on Nexus 5 and I observed that, I am not getting any error or exception when I try to tap on
"Sample Note" button. This application is working fine.

This issue has been fixed. Hence closing this issue.
Comment 5 Ram Chandra 2015-04-15 07:59:16 UTC
Also working fine on OS X environment:

=== Xamarin Studio ===

Version 5.9 (build 425)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: f7736a4
Build date: 2015-04-09 04:22:08-0400

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 509000425
Git revision: c980b9d4b7d6b36bd73f4ea681ce92498054c837
Build date: 2015-04-13 18:36:16-04
Xamarin addins: 57fcb30c57f28537bd2eb6f90e62a4b88d70531d

=== Operating System ===

Mac OS X 10.10.3
Darwin Dalvik.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64