dotnet / dotnet/reactive

ToLookup Operator Doesn't Work With Null Keys (behaviour differs to IEnumerable ToLookup)

Open
#1,722 0 comments 2 reactions 0 assignees View on GitHub
[area] Rx
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

#### Bug

> Which library version?

Tested with both 3.0.0 (what we are currently using) and 5.0.0.

> What are the platform(s), environment(s) and related component version(s)?

Windows 10, .NET 4.8

> What is the use case or problem?

The ToLookup operator cannot be created or indexed with null keys at all, the IEnumerable LINQ version can be.

> What is the expected outcome?

Creation of an ILookup with a null key entry to match the behaviour of `var lookup = new string?[] { "foo", null }.ToLookup(x => x);`

Successful lookups using the indexer with a null key.

> What is the actual outcome?

An ArgumentNullException is thrown.

> What is the stacktrace of the exception(s) if any?

Trying to create with null key:

at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Reactive.Lookup`2.Add(K key, E element) in /_/Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs:line 30
at System.Reactive.Linq.ObservableImpl.ToLookup`3._.OnNext(TSource value) in /_/Rx.NET/Source/src/System.Reactive/Linq/Observable/ToLookup.cs:line 54

For indexing with null key:

at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Reactive.Lookup`2.get_Item(K key) in /_/Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs:line 40

> Do you have a code snippet or project that reproduces the problem?

On creation:

var lookup = await new string?[] { "foo", null }.ToObservable().ToLookup(x => x);

And on lookups:

var lookup = await new string?[] { "foo", "bar" }.ToObservable().ToLookup(x => x);
var value = lookup[null];

Both of these examples work if you use the IEnumerable ToLookup operator.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.