DataTable.Compute throws exception on "true NOT= false"

Open
#115,649 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
databases

Research direction

Start with DataTable.Compute and the ExpressionParser.BuildExpression path shown in the stack trace, comparing how boolean equality and NOT expressions are parsed. Reproduce the failing expression and verify that it returns true without throwing, while the similar expressions and workaround continue to pass.

Written by the indexing model from the issue text.

Description

area-System.Data
Description

DataTable.Compute() throws a System.IndexOutOfRangeException on a simple expression: "true NOT= false".

Reproduction Steps
using System.Data;

new DataTable().Compute("true NOT= false", null);
Expected behavior

I would expect DataTable.Compute() to execute successfully and return true.

Similar expressions are evaluated successfully by DataTable.Compute().

using System.Data;
using System.Diagnostics;
					
Debug.Assert((bool)new DataTable().Compute("1 NOT= 2", null) == true);            // passes
Debug.Assert((bool)new DataTable().Compute("true = false", null) == false);       // passes
Debug.Assert((bool)new DataTable().Compute("true NOT= false", null) == true);     // exception thrown
Actual behavior

A System.IndexOutOfRangeException is thrown. Stack trace:

Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Data.ExpressionParser.BuildExpression(Int32 pri)
   at System.Data.ExpressionParser.Parse()
   at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)
   at System.Data.DataTable.Compute(String expression, String filter)
   at Program.Main()
Command terminated by signal 6
Regression?

No response

Known Workarounds

Can work around the problem by reformulating the expression:

using System.Data;
using System.Diagnostics;
					
Debug.Assert((bool)new DataTable().Compute("NOT(true = false)", null) == true);     // passes
Configuration

No response

Other information

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.