Bug 320229 (MONO77446) - [GMCS] Nullable types assignment crashes reflection
Summary: [GMCS] Nullable types assignment crashes reflection
Status: RESOLVED FIXED
Alias: MONO77446
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Major
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-02 13:50 UTC by Lev Walkin
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Shortest C# source exploiting the problem. (690 bytes, text/plain)
2006-02-02 13:51 UTC, Thomas Wiest
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:47:03 UTC


---- Reported by vlm@lionet.info 2006-02-02 06:50:19 MST ----

Please fill in this template when reporting a bug, unless you know what you are doing.
Description of Problem:

When a nullable member of a class is assigned, reflection crashes in mono_object_unbox
when trying to GetValue the object.

Steps to reproduce the problem:
1. Create a nullable string member of a class.
2. Assign this member of a class to some "value".
3. Use fieldInfo.GetValue() on that member. Experience assertion failure.

Actual Results:

[vlm@nala:~]> mono mono_object_unbox.exe 
This statement can be reached

** ERROR **: file object.c: line 2978 (mono_object_unbox): assertion failed: (obj->vtable->klass-
>valuetype)
aborting...
Abort trap
[vlm@nala:~]>

Expected Results:

[vlm@nala:~]> mono mono_object_unbox.exe 
This statement can be reached
THIS STATEMENT CANNOT BE REACHED
[vlm@nala:~]>


How often does this happen? 

100% reproducible.

Additional Information:

=========================================================
using System;
using System.Reflection;

public class UnboxingProblem {
        public string? s;

        public static void Main() {
                UnboxingProblem problem = new UnboxingProblem();

                FieldInfo[] fieldInfoList;
                fieldInfoList = problem.GetType()
                        .GetFields(BindingFlags.Public | BindingFlags.Instance);
                FieldInfo fieldInfo = fieldInfoList[0];

                object value = fieldInfo.GetValue(problem);
                if(value != null) Console.WriteLine("EXPECTATION FAILED");
                problem.s = "string";
                Console.WriteLine("This statement can be reached");
                value = fieldInfo.GetValue(problem);
                Console.WriteLine("THIS STATEMENT CANNOT BE REACHED");
                if(value == null) Console.WriteLine("EXPECTATION FAILED");
        }

}
==========================================================



---- Additional Comments From vlm@lionet.info 2006-02-02 06:51:24 MST ----

Created an attachment (id=169215)
Shortest C# source exploiting the problem.




---- Additional Comments From vargaz@gmail.com 2006-02-09 09:46:09 MST ----

Fixed in SVN HEAD and 1.1.13. BTW, using string? does not have any
advantage over using string, since reference types are already 'nullable'.




---- Additional Comments From vlm@lionet.info 2006-02-09 13:01:49 MST ----

String is of no importance; just for the sake of this test case.

Thanks!



---- Additional Comments From bmaurer@users.sf.net 2006-02-09 16:27:33 MST ----

This should not work in the first place:

C:\Program Files\Microsoft Visual Studio 8\VC>"C:\Documents and
Settings\bmaure
\Desktop\x.exe"

Unhandled Exception: System.TypeLoadException: GenericArguments[0],
'System.Str
ng', on 'System.Nullable`1[T]' violates the constraint of type
parameter 'T'.

Nullable<T> should be where T : struct. So the patch should probably
be backed out, and the signature on nullable fixed.



---- Additional Comments From vargaz@gmail.com 2006-02-10 16:39:08 MST ----

The Nullable signature is now fixed.




---- Additional Comments From vargaz@gmail.com 2006-02-11 07:54:57 MST ----

The runtime changes are also reverted, so the original testcase is
no longer valid.


Imported an attachment (id=169215)

Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>MacOS X 10.4</cf_op_sys_details>
Unknown operating system unknown. Setting to default OS "Other".