stanfordnlp/CoreNLP · warning

Unknown default unit

Error message

Unknown default unit ${entry.getValue().first} for ${entry.getKey()}

What it means

When loading quantity-expressor units, each unit's declared default unit name is looked up in unitsByName. If the referenced default unit was never defined (or misspelled / loaded out of order), the link cannot be made and a warning is emitted; the unit is loaded without a defaultUnit.

Solutions

  1. Fix the default unit name in the units file to exactly match a defined unit's name.
  2. Ensure the file defining the referenced unit is loaded before/along with the referencing file.
  3. Check case sensitivity — unit names are matched exactly via unitsByName.

Example fix

// before (units file): DEFAULT references misspelled 'kilometre' that doesn't exist
meter  LENGTH  metre  1.0  metres  m
// after: define the referenced unit
kilometre  LENGTH  kilometre  1000.0  kilometres  km
meter  LENGTH  metre  1.0  metres  m
Defensive patterns

Strategy: validation

Validate before calling

Set<String> defined = unitsByName.keySet();
for (entry : defaults) {
  if (!defined.contains(entry.getValue().first)) {
    throw new IllegalArgumentException("Unknown default unit: " + entry.getValue().first);
  }
}

Try / catch

try (BufferedReader br = ...) {
  return loadUnits(br);
} catch (Exception e) {
  log.warn("units file problem; continuing without default units", e);
  return Collections.emptyList();
}

Prevention

When it happens

Trigger: Units.loadUnits (invoked via the units setup) reading a units definition file whose default-unit column names a unit string not present in unitsByName at link time.

Common situations: Typo in the default unit name in a custom units file; referencing a unit defined in a different file that wasn't loaded; case mismatch since lookup is exact via the unitsByName map.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/qe/Units.java:154

      }
      if (fields.length > iDefaultUnit) {
        double scale = 1.0;
        if (fields.length > iDefaultUnitScale) {
          scale = Double.parseDouble(fields[iDefaultUnitScale]);
        }
        unitToDefaultUnits.put(unit.getName(), Pair.makePair(fields[iDefaultUnit], scale));
      }
      unitsByName.put(unit.getName(), unit);
      list.add(unit);
    }
    for (Map.Entry<String, Pair<String,Double>> entry: unitToDefaultUnits.entrySet()) {
      Unit unit = unitsByName.get(entry.getKey());
      Unit defaultUnit = unitsByName.get(entry.getValue().first);
      if (defaultUnit != null) {
        unit.defaultUnit = defaultUnit;
        unit.defaultUnitScale = entry.getValue().second;
      } else {
        Redwood.Util.warn("Unknown default unit " + entry.getValue().first + " for " + entry.getKey());
      }
    }
    br.close();
    return list;
  }

}

View on GitHub (pinned to 1b7edd19c4)