[Mono-bugs] [Bug 412965] New: MethodBuilder.SetReturnType (null) may cause NRE

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jul 29 12:14:32 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=412965


           Summary: MethodBuilder.SetReturnType (null) may cause NRE
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Minor
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: rkvinge at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Repro:

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;

class vbnc_bugs {
static void Main (string [] args) {

AppDomain domain = AppDomain.CurrentDomain;
AssemblyName name = new AssemblyName ("test");
AssemblyBuilder assembly = domain.DefineDynamicAssembly (name,
AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess) 0x800);
ModuleBuilder module = assembly.DefineDynamicModule ("module");

TypeBuilder TBase = module.DefineType ("TBase`1", TypeAttributes.Public, typeof
(List <>));
GenericTypeParameterBuilder [] TBaseParams = TBase.DefineGenericParameters (new
string [] {"T"});

TypeBuilder TList = module.DefineType ("TList`1", TypeAttributes.Public,
TBase);
TypeBuilder A = module.DefineType ("A", TypeAttributes.Public);
GenericTypeParameterBuilder [] TListParams = TList.DefineGenericParameters (new
string [] {"T"});
Type TListInst = TList.MakeGenericType (new Type [] {A});
MethodBuilder method = TList.DefineMethod ("Add", MethodAttributes.Public,
null, Type.EmptyTypes);
method.SetReturnType (null); // This is the problem
MethodInfo methodInst = TypeBuilder.GetMethod (TListInst, method);

Console.WriteLine (methodInst.GetType ().FullName);
Console.WriteLine (methodInst.DeclaringType.FullName);
Console.WriteLine (methodInst.ReturnType);
Console.WriteLine (method.ReturnType);

method.GetILGenerator ().EmitCall (OpCodes.Call, methodInst, null);

Console.WriteLine ("SUCCESS");


}
}

Expected output:
(...)
SUCCESS

Actual output:
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
  at System.Reflection.MonoGenericClass.InflateType (System.Type type)
[0x00000] in
/mono/main/src/mcs/class/corlib/System.Reflection/MonoGenericClass.cs:123 
  at System.Reflection.Emit.MethodOnTypeBuilderInst.get_ReturnType () [0x0002b]
in
/mono/main/src/mcs/class/corlib/System.Reflection.Emit/MethodOnTypeBuilderInst.cs:80 
  at vbnc_bugs.Main (System.String[] args) [0x000ec] in
/home/rolf/test/reflection.cs:29 
make: *** [reflection] Error 1
2


Note:
This only happen in Compiler mode (adding the 0x800 flag for
AssemblyBuilderAccess when creating the assembly). I've worked around this in
vbnc (using SetReturnType (System.Void) instead of null), so it's not a big
issue anymore (at least for me).

rolf at linux:~/test> mono --version
Mono JIT compiler version 2.0 (/trunk/mono r109155)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list