[Mono-bugs] [Bug 58864][Cri] New - Modulus operator comparison generates null value exception

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 22 May 2004 21:23:34 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by prp@teleport.com.

http://bugzilla.ximian.com/show_bug.cgi?id=58864

--- shadow/58864	2004-05-22 21:23:34.000000000 -0400
+++ shadow/58864.tmp.15083	2004-05-22 21:23:34.000000000 -0400
@@ -0,0 +1,152 @@
+Bug#: 58864
+Product: Mono: Runtime
+Version: unspecified
+OS: 
+OS Details: RedHat Fedora Core 1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Critical
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: prp@teleport.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Modulus operator comparison generates null value exception
+
+Please fill in this template when reporting a bug, unless you know what you 
+are doing.
+Description of Problem:
+
+
+Steps to reproduce the problem:
+1. Compile and run ModulusTest.cs below
+2. 
+3. 
+
+Actual Results:
+5 % 2 != 0: True
+4 % 2 != 0: False
+3 % 2 != 0: True
+2 % 2 != 0: False
+1 % 2 != 0: True
+0 % 2 != 0: False
+-1 % 2 != 0: True
+-2 % 2 != 0: False
+-3 % 2 != 0: True
+-4 % 2 != 0: False
+-5 % 2 != 0: True
+ 
+5 % 2 != 0: True
+4 % 2 != 0: False
+3 % 2 != 0: True
+2 % 2 != 0: False
+1 % 2 != 0: True
+0 % 2 != 0: False
+-1 % 2 != 0: A null value was found where an object instance was required.
+in <0x000c5> modulustest.ModulusTest:TestCase (long)
+in <0x001af> modulustest.ModulusTest:Main (string[])
+ 
+-2 % 2 != 0: False
+-3 % 2 != 0: A null value was found where an object instance was required.
+in <0x000c5> modulustest.ModulusTest:TestCase (long)
+in <0x001af> modulustest.ModulusTest:Main (string[])
+ 
+-4 % 2 != 0: False
+-5 % 2 != 0: A null value was found where an object instance was required.
+in <0x000c5> modulustest.ModulusTest:TestCase (long)
+in <0x001af> modulustest.ModulusTest:Main (string[])
+ 
+
+
+Expected Results:
+5 % 2 != 0: True
+4 % 2 != 0: False
+3 % 2 != 0: True
+2 % 2 != 0: False
+1 % 2 != 0: True
+0 % 2 != 0: False
+-1 % 2 != 0: True
+-2 % 2 != 0: False
+-3 % 2 != 0: True
+-4 % 2 != 0: False
+-5 % 2 != 0: True
+
+5 % 2 != 0: True
+4 % 2 != 0: False
+3 % 2 != 0: True
+2 % 2 != 0: False
+1 % 2 != 0: True
+0 % 2 != 0: False
+-1 % 2 != 0: True
+-2 % 2 != 0: False
+-3 % 2 != 0: True
+-4 % 2 != 0: False
+-5 % 2 != 0: True
+ 
+
+How often does this happen? 
+Always.
+
+Additional Information:
+
+$ mcs --version
+Mono C# compiler version 0.31.0.0
+$ mono --version
+Mono JIT compiler version 0.31, (C) 2002-2004 Novell, Inc and Contributors. 
+www.go-mono.com
+        TLS:           NPTL
+        GC:            Included Boehm (with typed GC)
+        Globalization: none
+
+ModulusTest.cs:
+
+using System;
+ 
+namespace modulustest
+{
+        public class ModulusTest
+        {
+                private bool v = false;
+ 
+                public ModulusTest()
+                {
+                }
+ 
+                public void TestCase(long i)
+                {
+                        Console.Out.Write(i + " % 2 != 0: ");
+                        v = i % 2 != 0;
+                        Console.Out.WriteLine(v);
+                }
+ 
+                [STAThread]
+                static void Main(string[] args)
+                {
+                        ModulusTest t = new ModulusTest();
+ 
+                        for (long i = 5; i >= -5; --i)
+                        {
+                                Console.Out.WriteLine(i + " % 2 != 0: " + 
+(i % 2 != 0).ToString());
+                        }
+                        Console.Out.WriteLine();
+ 
+                        for (long i = 5; i >= -5; --i)
+                        {
+                                try
+                                {
+                                        t.TestCase(i);
+                                }
+                                catch (Exception e)
+                                {
+                                        Console.Error.WriteLine(e.Message);
+                                        Console.Error.WriteLine(e.
+StackTrace);
+                                }
+                        }
+                }
+        }
+}