[Mono-bugs] [Bug 608282] New: Not-null string variable causes NullReferenceException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon May 24 09:50:41 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=608282

http://bugzilla.novell.com/show_bug.cgi?id=608282#c0


           Summary: Not-null string variable causes NullReferenceException
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.4.x
          Platform: 64bit
        OS/Version: openSUSE 11.2
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: GC
        AssignedTo: lupus at novell.com
        ReportedBy: goldywhite at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1064 Safari/532.5

I have string with value "EMETHA" stored in string field "name", property
"Name" overrides FieldInfo.Name. Object derived from FieldInfo stored in
ArrayList.
I retrive var s = obj.Name;
After that I try to work with variable s and takes NullReferenceException in
some cases.
Source of the string is function:
static string c_decode(this string ss){
char[] rc = new char[ss.Length];
for(var i = 0; i<ss.Length; i++) {
//some conditions
rc[z++] = s[i];
}
return new string(rc, 0, z);
}

Reproducible: Always

Steps to Reproduce:
I can't reproduce this string without full context. For example I make some
simplified classes with same structure but error doesn't occuired. In full
context and same arguments error occuires in 90% cases.
To reproduce error I call some methods on String object


Actual Results:  
s[0]:E
s.Clone():Object reference not set to an instance of an object
s.CompareTo("EMETHA"):0
s.Contains("E"):True
s.ToString():Object reference not set to an instance of an object
s.GetHashCode():Object reference not set to an instance of an object
unsafe code:
fixed (char* c = s) {
for (char* p = c, e = c + s.Length; p < e; p++)
{
    res.Append(*p);
    res.Append("(");
    res.Append(((int)*p).ToString("X2"));
    res.Append(") ");
}
}
produces this result:
E(45) M(4D) E(45) T(54) H(48) A(41)


var res = new StringBuilder();
            try
            {
                if (s == null)
                    res.Append("s == null");
                else
                {
                    try
                    {
                        res.AppendFormat("s[0]:{0}", s[0]);
                    }
                    catch(Exception e)
                    {
                        res.AppendFormat("s[0]:{0}", e.Message);
                    }
                    try
                    {
                        res.AppendFormat("s.Clone():{0}", s.Clone());
                    }
                    catch (Exception e)
                    {
                        res.AppendFormat("s.Clone():{0}", e.Message);
                    }
                    try
                    {
                        res.AppendFormat("s.CompareTo(\"EMETHA\"):{0}",
s.CompareTo("EMETHA"));
                    }
                    catch (Exception e)
                    {
                        res.AppendFormat("s.CompareTo(\"EMETHA\"):{0}",
e.Message);
                    }
                    try
                    {
                        res.AppendFormat("s.Contains(\"E\"):{0}",
s.Contains("E"));
                    }
                    catch (Exception e)
                    {
                        res.AppendFormat("s.Contains(\"E\"):{0}", e.Message);
                    }
                    try
                    {
                        res.AppendFormat("s.ToString():{0}", s.ToString());
                    }
                    catch (Exception e)
                    {
                        res.AppendFormat("s.ToString():{0}", e.Message);
                    }
                    try
                    {
                        res.AppendFormat("s.GetHashCode():{0}",
s.GetHashCode());
                    }
                    catch (Exception e)
                    {
                        res.AppendFormat("s.GetHashCode():{0}", e.Message);
                    }
                    unsafe
                    {
                        fixed (char* c = s)
                        {
                            for (char* p = c, e = c + s.Length; p < e; p++)
                            {
                                res.Append(*p);
                                res.Append("(");
                                res.Append(((int)*p).ToString("X2"));
                                res.Append(") ");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                res.AppendFormat("\nexception: {0}", e);
            }
            return res.ToString();

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


More information about the mono-bugs mailing list