Skip to content

LinkedMap.delete and LRUCache.delete return false for existing falsy values #1942

Closed

Description

Problem

The exported LinkedMap.delete(key) returns false for an existing entry when its stored value is falsy, even though it removes the entry. LRUCache inherits the same behavior.

Reproduced on main at 6a2f42f72b8b1f2317d6f61c3f8f327ed980e0d9 (vscode-jsonrpc 10.0.0), using Node.js 22.22.3 on macOS arm64.

Reproduction

From a compiled checkout:

const { LinkedMap, LRUCache } = require('./jsonrpc/lib/node/main');

for (const map of [new LinkedMap(), new LRUCache(3)]) {
  map.set('key', 0);
  console.log(map.has('key'));    // true
  console.log(map.delete('key')); // false; expected true
  console.log(map.has('key'));    // false
  console.log(map.delete('key')); // false; expected false
}

The same incorrect result occurs with false, '', null, undefined, and NaN. A truthy value returns true.

Expected behavior

Return whether the key existed and was removed, independently of its stored value. A missing key should still return false.

Cause and proposed fix

jsonrpc/src/common/linkedMap.ts implements deletion as return !!this.remove(key). Since remove returns the stored value, the boolean reflects value truthiness rather than key presence.

I have a small fix that checks key presence and retains the existing removal path, with regression coverage for both classes, falsy/truthy values, missing and repeated deletions, size, and iteration order. Both new tests fail on the original implementation; all 79 JSON-RPC Node tests pass with the fix. I plan to submit the corresponding PR.

This report and fix were prepared with Codex assistance.

Activity

  1. added this to the milestone on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions