Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IN operator not working with null value on nullable properties #1373

Closed
sebastienrob opened this issue Jan 8, 2019 · 0 comments

Comments

Projects
None yet
3 participants
@sebastienrob
Copy link

commented Jan 8, 2019

An NullReferenceException is thrown while parsing a filter expression with the IN operator and a null value for a nullable property.

The problem seems to be related to this line of code:

this.collection.Add(new ConstantNode(item, item.ToString(), this.itemType));

If item is NULL, then the call to ToString() will fail with a NullReferenceException.

Assemblies affected

ODataLib 7.5.3

Reproduce steps

Sample Model

public class TestEntity
{
   [Key]
   public int PropertyKey { get; set; }

   public int PropertyInt { get; set; }

   public int? NullablePropertyInt { get; set; }
}

Sample query

http://host/service/TestEntity?$filter=NullablePropertyInt in (1,2,null)

Expected result

The list of all the TestEntity with 1, 2 or NULL as the value of the property NullablePropertyInt.

Actual result

An NullReferenceException is thrown:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.OData.UriParser.CollectionConstantNode..ctor(IEnumerable`1 objectCollection, String literalText, IEdmCollectionTypeReference collectionType)
   at Microsoft.OData.UriParser.LiteralBinder.BindLiteral(LiteralToken literalToken)
   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
   at Microsoft.OData.UriParser.InBinder.GetCollectionOperandFromToken(QueryToken queryToken, IEdmTypeReference expectedType, IEdmModel model)
   at Microsoft.OData.UriParser.InBinder.BindInOperator(InToken inToken, BindingState state)
   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
   at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()

Additional detail

if we try the same query on the non nullable property, we are receiving an ODataException explaining the NULL value is not allowed, which is correct.

http://host/service/TestEntity?$filter=PropertyInt in (1,2,null)
Microsoft.OData.ODataException: A null value was found with the expected type 'Edm.Int32[Nullable=False]'. The expected type 'Edm.Int32[Nullable=False]' does not allow null values.
   at Microsoft.OData.ReaderValidationUtils.ThrowNullValueForNonNullableTypeException(IEdmTypeReference expectedValueTypeReference, String propertyName)
   at Microsoft.OData.ReaderValidationUtils.ValidateNullValueAllowed(IEdmTypeReference expectedValueTypeReference, Boolean validateNullValue, String propertyName, Nullable`1 isDynamicProperty)
   at Microsoft.OData.ReaderValidator.ValidateNullValue(IEdmTypeReference expectedTypeReference, Boolean validateNullValue, String propertyName, Nullable`1 isDynamicProperty)
   at Microsoft.OData.Json.ODataJsonReaderCoreUtils.TryReadNullValue(IJsonReader jsonReader, ODataInputContext inputContext, IEdmTypeReference expectedTypeReference, Boolean validateNullValue, String propertyName, Nullable`1 isDynamicProperty)
   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideResourceValue, String propertyName, Nullable`1 isDynamicProperty)
   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadCollectionValue(IEdmCollectionTypeReference collectionValueTypeReference, String payloadTypeName, ODataTypeAnnotation typeAnnotation)
   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, PropertyAndAnnotationCollector propertyAndAnnotationCollector, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideResourceValue, String propertyName, Nullable`1 isDynamicProperty)
   at Microsoft.OData.ODataUriConversionUtils.ConvertFromResourceOrCollectionValue(String value, IEdmModel model, IEdmTypeReference typeReference)
   at Microsoft.OData.UriParser.InBinder.GetCollectionOperandFromToken(QueryToken queryToken, IEdmTypeReference expectedType, IEdmModel model)
   at Microsoft.OData.UriParser.InBinder.BindInOperator(InToken inToken, BindingState state)
   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
   at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()

@KanishManuja-MS KanishManuja-MS added the bug label Jan 9, 2019

@madansr7 madansr7 added this to the 7.6 milestone Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.