pinpoint-apm/pinpoint · error · ResponseStatusException

Invalid serviceTypeCode

Error message

Invalid serviceTypeCode

What it means

ApplicationValidator.newApplication(name, serviceTypeCode) throws a 400 ResponseStatusException when the supplied serviceTypeCode equals the registry's 'undefined' code, meaning no real ServiceType was identified. The application cannot be registered without a valid service type.

Source

Thrown at web/src/main/java/com/navercorp/pinpoint/web/util/ApplicationValidator.java:34

    static final int UNDEFINED = ServiceType.UNDEFINED.getCode();
    static final int MAX_LENGTH = PinpointConstants.AGENT_NAME_MAX_LEN;

    private final ServiceTypeRegistryService registry;
    private final int undefined;

    public ApplicationValidator(ServiceTypeRegistryService registry) {
        this(registry, UNDEFINED);
    }

    public ApplicationValidator(ServiceTypeRegistryService registry, int undefined) {
        this.registry = Objects.requireNonNull(registry, "registry");
        this.undefined = undefined;
    }

    public Application newApplication(String applicationName, int serviceTypeCode) {
        validateName(applicationName);
        if (serviceTypeCode == undefined) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceTypeCode" + serviceTypeCode);
        }
        ServiceType serviceType = registry.findServiceType(serviceTypeCode);
        return new Application(applicationName, serviceType);
    }

    public Application newApplication(String applicationName, String serviceTypeName) {
        validateName(applicationName);
        if (!StringUtils.hasLength(serviceTypeName)) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceTypeName " + serviceTypeName);
        }
        ServiceType serviceType = registry.findServiceTypeByName(serviceTypeName);
        if (serviceType.getCode() == undefined) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid serviceTypeName " + serviceTypeName);
        }
        return new Application(applicationName, serviceType);
    }

    public Application newApplication(String applicationName, int serviceTypeCode, String serviceTypeName) {

View on GitHub (pinned to 744c3d3075)

Solutions

  1. Look up the correct serviceTypeCode from Pinpoint's ServiceType list (GET /serviceTypeInfo) and resend
  2. If you only know the type name, use the variant accepting serviceTypeName instead
  3. Check plugin/agent config that supplies the code for stale or default (0) values
  4. Update client code that hardcodes the code after a Pinpoint version upgrade changed the registry

Example fix

// before
newApplication("myApp", 0) // 0 = undefined
// after
newApplication("myApp", 1010) // e.g. STAND_ALONE code from serviceTypeInfo
Defensive patterns

Strategy: validation

Validate before calling

// Resolve a valid serviceTypeCode before building the application
const types = (await axios.get('/serviceTypeInfo')).data;
const code = 1010; // desired code
if (!types.some(t => t.code === code)) {
  throw new Error(`serviceTypeCode ${code} not registered`);
}

Type guard

function isDefinedCode(code, undefinedCode) {
  return Number.isInteger(code) && code !== undefinedCode && code > 0;
}

Try / catch

try {
  const app = newApplication(name, serviceTypeCode);
} catch (e) {
  if (e instanceof ResponseStatusException && e.getMessage().startsWith('Invalid serviceTypeCode')) {
    // fall back to name-based lookup or fix the code
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling an API that builds an Application from a numeric serviceTypeCode (e.g. POST /application) passing the sentinel undefined code (typically 0 or an unknown value) instead of a registered ServiceType code.

Common situations: Clients sending serviceTypeCode=0 or a default/uninitialized value; agent/plugin config where the service type code was changed and the old code is now undefined; copy-pasted sample payloads with placeholder codes.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/e8844120d5dddcc0. Report an issue: GitHub.