SimpleJSON.JSONXXX breaks Dictionary key semantics (Equals not reflexive) + mutable hash codes in value nodes (JSONBool/JSONString/JSONNumber)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by locating the JSONBool, JSONString, and JSONNumber equality and hash code implementations mentioned in the report, then reproduce the dictionary behavior with the supplied C# example. Compare the behavior before and after mutation, including the same-instance lookup immediately after insertion. Done means equality is reflexive and the reported collection behavior is addressed; the issue has had no comment for 199 days.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
I noticed that using SimpleJSON.JSONBool as a dictionary key: after adding an instance as a key, ContainsKey(sameInstance) returns false even before any mutation. This appears to be because JSONBool.Equals(object) returns true only when compared to a boxed bool, and returns false when compared to a JSONBool (including itself).
Several Issues:
JSONBool.Equalsis not reflexive (x.Equals(x)can be false), which breaks core .NET equality and collection semantics immediately.JSONBool/JSONString/JSONNumberhave hash codes derived from mutable state, so they’re unsafe in hash-based scenarios after mutation (including implicit hashing in LINQ- maybe-by-design???: cross-type equality (
JSONNumbervs numeric primitives,JSONStringvsstring) is inherently non-symmetric, so it should either be avoided, carefully documented, or implemented via explicit comparisons/conversions rather thanEquals
Mutable hash (JSONBool/JSONString/JSONNumber)
This can break any hash-based collection or algorithm if the node is mutated after being used as a key/element, for example:
HashSet<JSONBool>membership can "lose" an item after mutation for the same reason a dictionary key can
- LINQ methods that build internal hash sets/lookups (e.g., Distinct, Except, Intersect, GroupBy, ToLookup) can behave inconsistently if elements/keys mutate while participating
To Reproduce
small repro:
using System;
using System.Collections.Generic;
using SimpleJSON;
public static class Program
{
public static void Main()
{
const Int32 val = 1;
SimpleJSON.JSONBool jsonBool = new SimpleJSON.JSONBool(true);
Dictionary<SimpleJSON.JSONBool, Int32> dict = new Dictionary<SimpleJSON.JSONBool, Int32>();
dict.Add(jsonBool, val);
Int32 hash1 = jsonBool.GetHashCode();
Console.WriteLine("hashcode: " + hash1);
Console.WriteLine("containsKey: " + dict.ContainsKey(jsonBool));
Console.WriteLine("containsValue: " + dict.ContainsValue(val));
jsonBool.AsBool = false; // mutate the object in the dict to lose it
Int32 hash2 = jsonBool.GetHashCode();
Console.WriteLine("hashcode: " + hash2);
Console.WriteLine("containsKey: " + dict.ContainsKey(jsonBool));
Console.WriteLine("containsValue: " + dict.ContainsValue(val));
}
}
actual output:
hashcode: 1
containsKey: False
containsValue: True
hashcode: 0
containsKey: False
containsValue: True
Expected behavior
dict.ContainsKey(jsonBool)should return true immediately afterdict.Add(jsonBool, val)when using the same instance as the lookup key.x.Equals(x)equalstrue
- Lingua principale
- C#
- Stelle
- 170
- Fork
- 35
- Merge medio
- 2h 52m
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di danipen/TextMateSharp
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlForse già presa @alexeyfala l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
danipen/TextMateSharp#145 · 2 commenti ·
-
[Breaking]: Visibility of fields/properties/classes does not match upstream tm4e implementationAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
danipen/TextMateSharp#123 · 3 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 44/100
danipen/TextMateSharp#120 · 38 commenti · 1 reazione ·
-
good first issue
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
danipen/TextMateSharp#119 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
danipen/TextMateSharp#75 · 2 commenti ·
Tutte le issue di danipen/TextMateSharp
Issue simili
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Klyroo/klyroo-dashboard#12 ·
I maintainer di solito rispondono entro 1 giorno
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates onForse già presa @yadavraj2001 l’ha presa oggi. Apertadocumentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
juandresrodca/AdminForge#73 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[辞書] VIVANTAperta要トリアージ 辞書
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
christian-raj/S-Aloha#504 ·
-
Issue: Feature Request Xenonid
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno