stanfordnlp/CoreNLP · critical · RuntimeException

: Inconsistent u2b/b2u arrays.

Error message

: Inconsistent u2b/b2u arrays.

What it means

The Buckwalter transliteration utility keeps two parallel static character arrays (arabicChars and buckChars) that must be the same length to build the u2b/b2u maps. Its constructor throws this RuntimeException if the arrays drift out of sync — a build-time/initialization invariant that indicates corrupted source data, not user input.

Solutions

  1. Compare arabicChars and buckChars array lengths in Buckwalter.java and re-align them one-to-one.
  2. Restore the original Buckwalter.java from the official CoreNLP source for your version.
  3. If adding a new mapping, add both the Arabic character and its Buckwalter counterpart at the same index.
  4. Check that no stale patched class file shadows the corrected source in your classpath.

Example fix

// before (Buckwalter.java)
private static final char[] arabicChars = {'\u0621', '\u0622', '\u0623'};
private static final char[] buckChars   = {'\'', '|', '>', '<'};
// after (equal lengths)
private static final char[] arabicChars = {'\u0621', '\u0622', '\u0623', '\u0624'};
private static final char[] buckChars   = {'\'', '|', '>', '<'};
Defensive patterns

Strategy: try-catch

Validate before calling

// java: fail fast at startup if transliteration tables are inconsistent
try { new Buckwalter(); }
catch (RuntimeException e) {
  throw new IllegalStateException("Buckwalter class corrupted: " + e.getMessage());
}

Try / catch

static final Buckwalter BW;
static {
  try { BW = new Buckwalter(); }
  catch (RuntimeException e) {
    throw new ExceptionInInitializerError("Buckwalter tables inconsistent - restore original class: " + e.getMessage());
  }
}

Prevention

When it happens

Trigger: Instantiating new Buckwalter() when the class's arabicChars and buckChars arrays differ in length — only possible if the class source/constants were modified, patched, or bundled from mismatched versions.

Common situations: Manually edited or partially copied Buckwalter.java (adding a Buckwalter char without the Arabic counterpart); merging forks of CoreNLP with divergent transliteration tables; source corruption during vendoring of the library.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/Buckwalter.java:135

  private boolean unicode2Buckwalter = false;
  private final Map<Character,Character> u2bMap;
  private final Map<Character,Character> b2uMap;
  private ClassicCounter<String> unmappable;

  private static boolean DEBUG = false;
  private static final boolean PASS_ASCII_IN_UNICODE = true;
  private static boolean SUPPRESS_DIGIT_MAPPING_IN_B2A = true;
  private static boolean SUPPRESS_PUNC_MAPPING_IN_B2A = true;

  //wsg: I have included _ in this list, which actually maps to tatweel.
  //In practice we strip tatweel as part of orthographic normalization,
  //so any instances of _ in the Buckwalter should actually be treated as
  //punctuation.
  private static final Pattern latinPunc = Pattern.compile("[\"\\?%,-;\\._]+");

  public Buckwalter() {
    if (arabicChars.length != buckChars.length)
      throw new RuntimeException(this.getClass().getName() + ": Inconsistent u2b/b2u arrays.");

    u2bMap = Generics.newHashMap(arabicChars.length);
    b2uMap = Generics.newHashMap(buckChars.length);
    for (int i = 0; i < arabicChars.length; i++) {
      Character charU = Character.valueOf(arabicChars[i]);
      Character charB = Character.valueOf(buckChars[i]);
      u2bMap.put(charU, charB);
      b2uMap.put(charB, charU);
    }

    if (DEBUG) unmappable = new ClassicCounter<>();
  }

  public Buckwalter(boolean unicodeToBuckwalter) {
    this();
    unicode2Buckwalter = unicodeToBuckwalter;
  }

View on GitHub (pinned to 1b7edd19c4)