github/copilot-sdk · error · IllegalArgumentException

Failed to apply default value ' + defaultValue + ' for…

Error message

Failed to apply default value ' + defaultValue + ' for parameter ' + param.name() + ' of type + type.getSimpleName()

What it means

Thrown by ParamCoercion.coerceDefault when a Param's declared string default value cannot be parsed into the parameter's Java type. Simple defaults are parsed directly; otherwise the string is treated as JSON via mapper.readValue. Any failure is wrapped in this IllegalArgumentException, preserving the default value text, parameter name, and target type in the message.

Solutions

  1. Fix the @Param defaultValue string so it parses as JSON for the declared type (quote strings, use bare numerics)
  2. Test the default by coercing it at startup rather than first invocation
  3. Remove the defaultValue and require an explicit argument if no valid default exists
  4. Read ex.getCause() (the Jackson exception) to see exactly why the string failed to parse

Example fix

// before
Param<String> name = Param.of("name", String.class, "unknown-tool"); // invalid JSON for String
// after
Param<String> name = Param.of("name", String.class, "\"unknown-tool\"");
Defensive patterns

Strategy: validation

Validate before calling

mapper.readValue(defaultValue, declaredType); // call once at startup to validate @Param defaults

Type guard

null

Try / catch

try { tool.invoke(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Failed to apply default value")) { /* fix the Param's defaultValue string */ } else { throw e; } }

Prevention

When it happens

Trigger: Declaring @Param(defaultValue="...") whose string is not valid JSON for the type — e.g. defaultValue="abc" for an int, unquoted text for String, or malformed JSON for a List/Map.

Common situations: Authors forget to JSON-quote string defaults (need "\"abc\"" not "abc"); typos in numeric defaults; defaults written for one type then the parameter type changed.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/82bbd38ece915714. Report an issue: GitHub.

Appendix: source

Thrown at java/sdk/src/main/java/com/github/copilot/rpc/ParamCoercion.java:170

            if (type == Short.class || type == short.class) {
                return (T) Short.valueOf(defaultValue);
            }
            if (type == Byte.class || type == byte.class) {
                return (T) Byte.valueOf(defaultValue);
            }
            if (type == Boolean.class || type == boolean.class) {
                return (T) Boolean.valueOf(defaultValue);
            }
            if (type.isEnum()) {
                Class<? extends Enum> enumType = (Class<? extends Enum>) type;
                return type.cast(Enum.valueOf(enumType, defaultValue));
            }
            // Fallback: let ObjectMapper parse the JSON-encoded default string
            return mapper.readValue(defaultValue, type);
        } catch (IllegalArgumentException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new IllegalArgumentException("Failed to apply default value '" + defaultValue + "' for parameter '"
                    + param.name() + "' of type " + type.getSimpleName(), ex);
        }
    }

    /**
     * Returns an empty Optional variant for Optional primitive types, or
     * {@code null} for all other types.
     *
     * @param type
     *            the declared parameter type
     * @return {@link java.util.OptionalInt#empty()},
     *         {@link java.util.OptionalLong#empty()},
     *         {@link java.util.OptionalDouble#empty()}, or {@code null}
     */
    static Object emptyOptionalOrNull(Class<?> type) {
        if (type == java.util.OptionalInt.class) {
            return java.util.OptionalInt.empty();
        }

View on GitHub (pinned to cd8cf15dc3)