[Mono-bugs] [Bug 470451] New: null reference in TreeView/MouseMoveHandler

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jan 28 18:57:31 EST 2009


           Summary: null reference in TreeView/MouseMoveHandler
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: djlawler at aol.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Description of Problem:
This bug happens using the multi-select treeview at this url:

The multi-select treeview uses the standard TreeView as it's base class but
overrides OnBeforeSelect and e.Cancel's it so that it can control the node
selections.  If the treeview control loses focus, then you click on a node
while moving the mouse the Mono treeview will blow up in the MouseMoveHandler
code with null reference exceptions on one of two assignments (I have not seen
it blow on the highlighted_node).  What happens is that when you click (mouse
down) back on the treeview, the Mono TreeView control regains focus
(GotFocusHandler) and it attempts to set a selected node of some sort (if the
selected_node is currently null).  However when it gets to the (set)
SelectedNode method it calls 'OnBeforeSelect' which is then cancelled by the
multiselect treeview.  This means that when it gets to the MouseMoveHandler
method (because not only did we click on a node but we were moving the mouse)
the selected_node (and focused_node) could very well be null.  As there is no
null checking it blows up.  I have to assume that while unusual, it is 'legal'
for the multi-select treeview to set e.Cancel to true in OnBeforeSelect.  To me
that means that the absense of null checking in the MouseMoveHandler routine is
a bug.  In fact it seems that just about everywhere else in the treeview
the null checking of selected_node is done (OnKeyDown, GotFocusHandler, etc.

Steps to reproduce the problem:
1. Use the following short program:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
    public class MyTreeView : TreeView
        protected override void OnBeforeSelect(TreeViewCancelEventArgs e)
            e.Cancel = true;


    public class Form1 : Form
        public Form1()

        private System.ComponentModel.IContainer components = null;
        private MyTreeView treeView1;

        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        private void InitializeComponent()
            System.Windows.Forms.TreeNode treeNode1 = new
            System.Windows.Forms.TreeNode treeNode2 = new
            System.Windows.Forms.TreeNode treeNode3 = new
            System.Windows.Forms.TreeNode treeNode4 = new
            System.Windows.Forms.TreeNode treeNode5 = new
            System.Windows.Forms.TreeNode treeNode6 = new
            System.Windows.Forms.TreeNode treeNode7 = new
            System.Windows.Forms.TreeNode treeNode8 = new
            System.Windows.Forms.TreeNode treeNode9 = new
            System.Windows.Forms.TreeNode treeNode10 = new
System.Windows.Forms.TreeNode("Node0", new System.Windows.Forms.TreeNode[] {
                treeNode1, treeNode2, treeNode3, treeNode4, treeNode5,
treeNode6, treeNode7, treeNode8, treeNode9});
            this.treeView1 = new MyTreeView();
            this.treeView1.Location = new System.Drawing.Point(13, 13);
            this.treeView1.Name = "treeView1";
            treeNode1.Name = "Node1";
            treeNode1.Text = "Node1";
            treeNode2.Name = "Node2";
            treeNode2.Text = "Node2";
            treeNode3.Name = "Node3";
            treeNode3.Text = "Node3";
            treeNode4.Name = "Node4";
            treeNode4.Text = "Node4";
            treeNode5.Name = "Node5";
            treeNode5.Text = "Node5";
            treeNode6.Name = "Node6";
            treeNode6.Text = "Node6";
            treeNode7.Name = "Node7";
            treeNode7.Text = "Node7";
            treeNode8.Name = "Node8";
            treeNode8.Text = "Node8";
            treeNode9.Name = "Node9";
            treeNode9.Text = "Node9";
            treeNode10.Name = "Node0";
            treeNode10.Text = "Node0";
            this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[]
            this.treeView1.Size = new System.Drawing.Size(267, 237);
            this.treeView1.TabIndex = 0;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(368, 262);
            this.Name = "Form1";
            this.Text = "Form1";

    static class Program
        static void Main()
            Application.Run(new Form1());

2. If you run this program on Mono (latest SVN) it will blow up if you start
the program, expand the treeview, do something so that the application loses
focus.  Then click on a node while moving the mouse.

Actual Results:

System.NullReferenceException: Object reference not set to an instance of an
object in System.Windows.Forms.TreeView.MouseMoveHandler

Expected Results:

There should be no null references

How often does this happen? 

Every time

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