From: Date: July 22 2008 3:51pm Subject: Connector/NET commit: r1348 - in branches/5.1: . Driver/Source TestSuite/Source List-Archive: http://lists.mysql.com/commits/50196 X-Bug: 38276 Message-Id: <200807221351.m6MDpfJh026081@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.1/CHANGES branches/5.1/Driver/Source/command.cs branches/5.1/TestSuite/Source/CommandTests.cs Log: Fixed problem where executing a command with a null connection object would result in a null reference exception instead of an InvalidOp (bug #38276) Modified: branches/5.1/CHANGES =================================================================== --- branches/5.1/CHANGES 2008-07-22 13:29:01 UTC (rev 1347) +++ branches/5.1/CHANGES 2008-07-22 13:51:41 UTC (rev 1348) @@ -10,6 +10,8 @@ - Improved documentation concerning autoincrement columns and the DataColumn class (bug #37350) - Fixed problem where executing a command that results in a fatal exception would not close the connection. (bug #37991) + - Fixed problem where executing a command with a null connection object would result in + a null reference exception instead of an InvalidOp (bug #38276) Version 5.1.6 - 5/7/08 - Fixed problem where parameters lists were not showing when you tried to alter a routine Modified: branches/5.1/Driver/Source/command.cs =================================================================== --- branches/5.1/Driver/Source/command.cs 2008-07-22 13:29:01 UTC (rev 1347) +++ branches/5.1/Driver/Source/command.cs 2008-07-22 13:51:41 UTC (rev 1348) @@ -272,10 +272,12 @@ private void CheckState() { // There must be a valid and open connection. - if ((connection == null || connection.State != ConnectionState.Open) && - !connection.SoftClosed) - throw new InvalidOperationException("Connection must be valid and open"); + if (connection == null) + throw new InvalidOperationException("Connection must be valid and open."); + if (connection.State != ConnectionState.Open && !connection.SoftClosed) + throw new InvalidOperationException("Connection must be valid and open."); + // Data readers have to be closed first if (connection.Reader != null && cursorPageSize == 0) throw new MySqlException("There is already an open DataReader associated with this Connection which must be closed first."); Modified: branches/5.1/TestSuite/Source/CommandTests.cs =================================================================== --- branches/5.1/TestSuite/Source/CommandTests.cs 2008-07-22 13:29:01 UTC (rev 1347) +++ branches/5.1/TestSuite/Source/CommandTests.cs 2008-07-22 13:51:41 UTC (rev 1348) @@ -426,6 +426,24 @@ cmd.Connection = c; Assert.AreEqual(66, cmd.CommandTimeout); } + + /// + /// Bug #38276 Short circuit evaluation error in MySqlCommand.CheckState() + /// + [Test] + public void SetNullConnection() + { + MySqlCommand command = new MySqlCommand(); + command.CommandText = "SELECT 1"; + command.Connection = null; + try + { + object o = command.ExecuteScalar(); + } + catch (InvalidOperationException) + { + } + } }