NightOwl888 commented on issue #1226:
URL: https://github.com/apache/lucenenet/issues/1226#issuecomment-3588505803
Thanks for the report.
None of the BCL collection types are structurally formattable and
`Dictionary<TKey, TValue>` wasn't replaced everywhere with
`JCG.Dictionary<TKey, TValue>` because we used to have a wrapped implementation
that was slower than the BCL type to handle `null` keys. However, since J2N
2.1.0, we have a low-level dictionary that will perform about the same on .NET
Core and probably faster on .NET Framework than the BCL types.
### Short Term
There are 2 potential fixes for this issue:
1. Replace `Dictionary<TKey, TValue>` with `JCG.Dictionary<TKey, TValue>`
(preferred)
2. Use `J2N.Text.StringFormatter` as the `IFormatProvider` in
`string.Format()`
### Long Term
Longer term, we should do a review on the whole solution to catch issues
such as this.
#### Option A
Create a Roslyn analyzer to catch scenarios where we are formatting
collection types (or collection interfaces) to ensure the underlying
implementation is structurally formattable (as well as any nested collections).
- The analyzer should check for string concatenation, `string.Format()` and
string interpolation
- The code fix should be:
- If the collection is only created inside of the current type and there
is a structurally formattable J2N replacement, the J2N replacement should be
used. Note that `ConcurrentDictionary<TKey, TValue>` has no replacement in J2N.
- If the collection is passed into the current type (thus we cannot
control the collection type), the code fix should be to use
`J2N.Text.StringFormatter`.
This would be preferable because it would check for regressions on this
issue in future versions of Lucene.NET.
#### Option B
A quick fix for this Lucene.NET release would be to simply replace all
`Dictionary<TKey, TValue>` instances with `JCG.Dictionary<TKey, TValue>`
throughout the solution. This will catch any potential issues where a `null`
key was allowed in Lucene but they didn't create any tests to confirm `null`
keys would work.
Of course, as previously mentioned, there may be cases where the collection
is passed in through the constructor or set through a field or property using
an interface and we don't have control over the collection type. In those
cases, we should use `J2N.Text.StringFormatter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]