stanfordnlp/CoreNLP · error · OneToOneMapException

Error: cannot insert multiple keys with the same value

Error message

Error: cannot insert multiple keys with the same value

What it means

OneToOneMap maintains a strict bijection: each left value maps to exactly one right value and vice versa. put(l, r) throws OneToOneMapException when adding an entry would reuse either side in a way that breaks the bijection (hasLeft != hasRight indicates one of l or r is already bound to a different partner). It refuses partial overwrites so the map never silently loses a mapping.

Solutions

  1. Remove the existing conflicting entry first before inserting the new pair
  2. Deduplicate your input data so each left and right value appears at most once
  3. Call containsLeft/containsRight (or check the backing maps) before put to detect collisions
  4. If you need many-to-one semantics, use a regular HashMap instead of OneToOneMap

Example fix

// before
map.put("a", 1); map.put("b", 1); // duplicate right value
// after
if (map.containsRight(1)) { map.removeRight(1); }
map.put("b", 1); // or use HashMap for non-bijective mappings
Defensive patterns

Strategy: validation

Validate before calling

// before put
if (map.containsKey(l) || map.containsValue(r)) {
  throw new IllegalArgumentException("Collision: " + l + " or " + r + " already bound");
}

Try / catch

try {
  map.put(l, r);
} catch (OneToOneMapException e) {
  logger.warning("Bijective conflict for (" + l + ", " + r + "); removing old bindings");
  // remove conflicting entries then retry
}

Prevention

When it happens

Trigger: Calling put(l, r) where l is already mapped to a different r, or r is already mapped to a different l — i.e. any duplicate left or duplicate right key.

Common situations: Loading a mapping table (e.g. label-to-id) with duplicate values on either side; merging two datasets whose mappings collide; assuming put behaves like HashMap.put and overwrites.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/b3fa1e3f17902871. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/OneToOneMap.java:60

  {
    return m_leftAsKey.isEmpty();
  }



  public int size()
  {
    return m_leftAsKey.size();
  }

  public void put(L l,R r) throws OneToOneMapException
  {
    boolean hasLeft = m_leftAsKey.containsKey(l);
    boolean hasRight = m_rightAsKey.containsKey(r);


    if(hasLeft != hasRight)
      throw new OneToOneMapException("Error: cannot insert multiple keys with the same value");

    m_leftAsKey.put(l,r);
    m_rightAsKey.put(r, l);
  }



  public R getLeftAsKey(L l)
  {
    return m_leftAsKey.get(l);
  }



  public L getRightAsKey(R r)
  {
    return m_rightAsKey.get(r);
  }

View on GitHub (pinned to 1b7edd19c4)