Bug 5980 - Using "object" in "AsyncTask" results in "NullReferenceException"
Summary: Using "object" in "AsyncTask" results in "NullReferenceException"
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: Highest major
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2012-07-04 10:08 UTC by Sebastian Krysmanski
Modified: 2014-01-22 08:22 UTC (History)
5 users (show)

Tags:
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:
Status:
VERIFIED FIXED

Description Sebastian Krysmanski 2012-07-04 10:08:31 UTC
I've created a sub class of AsyncTask like this:

  class AsyncTestRunner : AsyncTask<object, int, object> {
  
    protected override object RunInBackground(params object[] @params) {
      return null;
    }
  }

Now, when I call "Execute()" I get a "NullReferenceException":

  AsyncTestRunner runner = new AsyncTestRunner();
  runner.Execute(); // NullReferenceException

Additionally I get this output on the console:

  07-04 16:01:06.511 W/dalvikvm( 5871): JNI WARNING: non-nullable const char* was NULL
  07-04 16:01:06.511 W/dalvikvm( 5871):              in Lmono/java/lang/RunnableImplementor;.n_run:()V (FindClass)
  07-04 16:01:06.511 I/dalvikvm( 5871): "main" prio=5 tid=1 NATIVE
  07-04 16:01:06.511 I/dalvikvm( 5871):   | group="main" sCount=0 dsCount=0 obj=0x40a25460 self=0x706828
  07-04 16:01:06.511 I/dalvikvm( 5871):   | sysTid=5871 nice=0 sched=0/0 cgrp=default handle=1074705544
  07-04 16:01:06.515 I/dalvikvm( 5871):   | schedstat=( 0 0 0 ) utm=81 stm=16 core=0
  07-04 16:01:06.515 I/dalvikvm( 5871):   at mono.java.lang.RunnableImplementor.n_run(Native Method)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at android.os.Handler.handleCallback(Handler.java:605)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at android.os.Handler.dispatchMessage(Handler.java:92)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at android.os.Looper.loop(Looper.java:137)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at android.app.ActivityThread.main(ActivityThread.java:4424)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at java.lang.reflect.Method.invokeNative(Native Method)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at java.lang.reflect.Method.invoke(Method.java:511)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  07-04 16:01:06.515 I/dalvikvm( 5871):   at dalvik.system.NativeStart.main(Native Method)
  07-04 16:01:06.515 I/dalvikvm( 5871): 
  07-04 16:01:06.519 E/dalvikvm( 5871): VM aborting
  07-04 16:01:06.519 I/mono    ( 5871): Stacktrace:
  07-04 16:01:06.519 I/mono    ( 5871): 
  07-04 16:01:06.519 I/mono    ( 5871):   at Android.Runtime.JNIEnv.FindClass (string) [0x00000] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:256
  07-04 16:01:06.519 I/mono    ( 5871):   at Android.Runtime.JNIEnv.FindClass (System.Type) [0x00009] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:233
  07-04 16:01:06.519 I/mono    ( 5871):   at Android.Runtime.JNIEnv.NewObjectArray<T> (T[]) [0x00044] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:1078
  07-04 16:01:06.519 I/mono    ( 5871):   at Android.OS.AsyncTask`3<object, int, object>.Execute (object[]) [0x0002d] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/src/Android.OS/AsyncTask.cs:69
  07-04 16:01:06.519 I/mono    ( 5871):   at MonoDroidUnit.GuiTestRunnerActivity/AsyncTestRunner.Run (Android.Content.Context,System.Func`1<MonoDroidUnitTesting.TestRunner>,System.Action`1<MonoDroidUnitTesting.TestRunner>) [0x0000a] in D:\Users\krysmasn\Documents\Andere Projekte\MonoDroidUnit\MonoDroidUnit\GuiTestRunnerActivity.cs:78
  07-04 16:01:06.519 I/mono    ( 5871):   at MonoDroidUnit.GuiTestRunnerActivity.RunTests () [0x00001] in D:\Users\krysmasn\Documents\Andere Projekte\MonoDroidUnit\MonoDroidUnit\GuiTestRunnerActivity.cs:38
  07-04 16:01:06.519 I/mono    ( 5871):   at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:32
  07-04 16:01:06.519 I/mono    ( 5871):   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00008] in /Users/builder/data/lanes/monodroid-mac-4.2-series/804357b4/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Java.Lang.IRunnable.cs:69
  07-04 16:01:06.519 I/mono    ( 5871):   at (wrapper dynamic-method) object.d2c68f67-6e3a-49cf-adda-6f844dc4d2f6 (intptr,intptr) <IL 0x0000c, 0x0002b>
  07-04 16:01:06.523 I/mono    ( 5871):   at (wrapper native-to-managed) object.d2c68f67-6e3a-49cf-adda-6f844dc4d2f6 (intptr,intptr) <IL 0x0001e, 0xffffffff>
  Unhandled Exception:

  System.NullReferenceException: Object reference not set to an instance of an object
Comment 1 Jonathan Pryor 2013-06-05 21:12:50 UTC
Fixed in monodroid/c7f4d852.
Comment 2 Sadik Ali 2014-01-22 08:22:06 UTC
I have verified this issue on following environment:

Window
XS 4.2.3 (build 154)
SA 4.13.0

Refer screen cast: http://screencast.com/t/u31wCZ8qd