alibaba/nacos · error · IllegalArgumentException

malformed factor

Error message

malformed factor

What it means

Thrown by validateHealthParams when healthParams.getFactor() is outside the range [0, 1]. The factor is the re-evaluation factor for response-time-based health-check interval adjustment. It must be a float between 0.0 and 1.0 inclusive.

Source

Thrown at naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java:398

    /**
     * Validate health params.
     *
     * @param healthParams health params
     */
    public void validateHealthParams(SwitchDomain.HealthParams healthParams) {
        if (healthParams.getMin() < SwitchDomain.HttpHealthParams.MIN_MIN) {
            throw new IllegalArgumentException("min check time for http or tcp is too small(<500)");
        }
        
        if (healthParams.getMax() < SwitchDomain.HttpHealthParams.MIN_MAX) {
            
            throw new IllegalArgumentException(
                "max check time for http or tcp is too small(<3000)");
        }
        
        if (healthParams.getFactor() < 0 || healthParams.getFactor() > 1) {
            
            throw new IllegalArgumentException("malformed factor");
        }
    }
    
    private void updateWithConsistency(SwitchDomain tempSwitchDomain) throws NacosException {
        try {
            final BatchWriteRequest req = new BatchWriteRequest();
            String switchDomainKey = KeyBuilder.getSwitchDomainKey();
            Datum datum = Datum.createDatum(switchDomainKey, tempSwitchDomain);
            req.append(ByteUtils.toBytes(switchDomainKey), serializer.serialize(datum));
            WriteRequest operationLog = WriteRequest.newBuilder().setGroup(group())
                .setOperation(OldDataOperation.Write.getDesc())
                .setData(ByteString.copyFrom(serializer.serialize(req)))
                .build();
            protocolManager.getCpProtocol().write(operationLog);
        } catch (Exception e) {
            Loggers.RAFT.error("Submit switch domain failed: ", e);
            throw new NacosException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        }

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Set 'factor' to a float in [0.0, 1.0], e.g. 0.85.
  2. If you think in percentages, divide by 100 before sending.

Example fix

// before
PUT /v3/admin/ns/operator/switches?entry=httpHealthParams&value={"min":500,"max":5000,"factor":85}
// after
PUT /v3/admin/ns/operator/switches?entry=httpHealthParams&value={"min":500,"max":5000,"factor":0.85}
Defensive patterns

Strategy: validation

Validate before calling

float factor = healthParams.getFactor();
if (factor < 0 || factor > 1) {
    throw new IllegalArgumentException("Health check factor must be in [0.0, 1.0]");
}

Type guard

function isValidFactor(factor: number): boolean {
  return factor >= 0 && factor <= 1;
}

Try / catch

try {
  operatorV2Impl.updateSwitch(entry, json, debug);
} catch (NacosApiException e) {
  if (e.getMessage().includes("malformed factor")) {
    params.factor = 0.85;
    json = JSON.stringify(params);
  }
}

Prevention

When it happens

Trigger: PUT /v3/admin/ns/operator/switches with entry=httpHealthParams or tcpHealthParams and a valid JSON whose 'factor' field is < 0 or > 1, e.g. {"min":500,"max":5000,"factor":1.5} or {"min":500,"max":5000,"factor":-0.1}.

Common situations: Passing factor as a percentage (e.g. 85 instead of 0.85), or typo in decimal placement.

Understand the failure class

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/34c8b29ae12f3b7e. Report an issue: GitHub.