apache/hadoop · error · Error

{} is not a number

Error message

{} is not a number

What it means

json-bignum.js (bundled with the HDFS web UIs to parse JSON containing 64-bit numbers) wraps values in BigNumber; the constructor does number.toString() and throws Error(number + ' is not a number') when isNaN(parseFloat(...)) is true or isFinite(...) is false. Anything that does not start with a parseable finite numeric string is rejected at construction time.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/json-bignum.js:64

    NOT CONTROL.
*/

/*jslint for */

/*property
    at, b, call, charAt, f, fromCharCode, hasOwnProperty, message, n, name,
    prototype, push, r, t, text
*/

(function(exports) {

  function BigNumber(number) {
    this.numberStr = number.toString();

    // not a number
    if (isNaN(parseFloat(this.numberStr)) === true
        || isFinite(this.numberStr) === false) {
        throw new Error(number + ' is not a number');
    }
  }

  BigNumber.prototype.toString = function() {
    return this.numberStr;
  }

exports.JSONParseBigNum = (function () {


// This is a function that can parse a JSON text, producing a JavaScript
// data structure. It is a simple, recursive descent parser. It does not use
// eval or regular expressions, so it can be used as a model for implementing
// a JSON parser in other languages.

// We are defining the function inside of another function to avoid creating
// global variables.

View on GitHub (pinned to 2add963021)

Solutions

  1. Default and validate before wrapping: treat null/undefined/'' as 0 or skip the value
  2. Gate with Number.isFinite(Number(x)) and only then construct BigNumber(x)
  3. Fix the data producer so numeric fields are always present and numeric in the JSON payload

Example fix

// before
const bn = new BigNumber(json.txid); // undefined when field absent -> throws

// after
const raw = json.txid;
const bn = new BigNumber(Number.isFinite(Number(raw)) ? raw : 0);
Defensive patterns

Strategy: type-guard

Validate before calling

function toBigNumber(raw, fallback) {
  return isBigNumberInput(raw) ? new BigNumber(raw) : new BigNumber(fallback || 0);
}

Type guard

function isBigNumberInput(v) {
  if (typeof v === 'number') return Number.isFinite(v);
  if (typeof v !== 'string') return false;
  return /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(v.trim());
}

Try / catch

try {
  var bn = new BigNumber(value);
} catch (e) {
  if (/is not a number$/.test(e.message)) { /* default or skip */ }
  else throw e;
}

Prevention

When it happens

Trigger: new BigNumber(undefined), new BigNumber(null), new BigNumber(''), new BigNumber('abc'), NaN or Infinity — e.g. feeding a missing JSON field (undefined after property access), a null counter, or an unvalidated string into the constructor.

Common situations: HDFS web UI JavaScript reading optional fields that the server omits or returns as null; passing user/query parameters straight into BigNumber; empty-string defaults from form inputs.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/123c33e28a8bd35e. Report an issue: GitHub.