{"record":{"id":"e7663a9aac32659c","repo":"apple/pkl","slug":"type-argument-s-for-type-parameter-s-is-not","errorCode":null,"errorMessage":"Type argument `%s` for type parameter `%s` is not within bound `%s`.","messagePattern":"Type argument `(.+?)` for type parameter `(.+?)` is not within bound `(.+?)`\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pkl-config-java/src/main/java/org/pkl/config/java/mapper/Types.java","lineNumber":59,"sourceCode":"      throw new IllegalArgumentException(\n          String.format(\n              \"Expected %d type arguments for `%s`, but got %d.\",\n              typeParamsCount, rawType.getTypeName(), typeArguments.length));\n    }\n    for (Type arg : typeArguments) {\n      if (arg instanceof Class<?> clazz) {\n        if (clazz.isPrimitive()) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"`%s.class` is not a valid type argument. Did you mean `%s.class`?\",\n                  clazz, Reflection.toWrapperType(clazz).getSimpleName()));\n        }\n      }\n    }\n    try {\n      return (ParameterizedType) TypeFactory.parameterizedClass(rawType, typeArguments);\n    } catch (TypeArgumentNotInBoundException e) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Type argument `%s` for type parameter `%s` is not within bound `%s`.\",\n              e.getArgument().getTypeName(),\n              e.getParameter().getTypeName(),\n              e.getBound().getTypeName()));\n    }\n  }\n\n  public static ParameterizedType optionalOf(Type elementType) {\n    return parameterizedType(Optional.class, elementType);\n  }\n\n  public static Type arrayOf(Type elementType) {\n    return TypeFactory.arrayOf(elementType);\n  }\n\n  public static ParameterizedType pairOf(Type firstType, Type secondType) {\n    return parameterizedType(Pair.class, firstType, secondType);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-config-java/src/main/java/org/pkl/config/java/mapper/Types.java#L41-L77","documentation":"After building the parameterized type via Jackson's TypeFactory, a TypeArgumentNotInBoundException indicates a type argument violates the bound declared on the type parameter (e.g. List<Number> for T extends Comparable). It is rethrown as an IllegalArgumentException naming the argument, parameter, and bound.","triggerScenarios":"parameterizedType(SomeClass.class, arg.class) where arg does not satisfy SomeClass's declared type-parameter bound, e.g. Types.pairOf on a class declaring <T extends Number> with String.class.","commonSituations":"Using generic container classes with constrained type parameters; hierarchy refactors that tighten a bound while call sites still pass the old type.","solutions":["Pass a type argument that satisfies the declared bound shown in the message.","Read the type parameter's declaration on the raw class to see the required bound.","Loosen the bound on the generic class if the wider type is intended."],"exampleFix":"// before\nTypes.parameterizedType(NumberBox.class, String.class); // T extends Number\n// after\nTypes.parameterizedType(NumberBox.class, Integer.class);","handlingStrategy":"validation","validationCode":"check each type argument satisfies the raw class's declared TypeVariable bounds before calling","typeGuard":null,"tryCatchPattern":"try { Types.parameterizedType(raw, args); } catch (IllegalArgumentException e) { /* message names argument, parameter and bound */ }","preventionTips":["Read the generic class's bound declarations (e.g. <T extends Number>) before choosing arguments","After tightening a bound in a refactor, grep all parameterizedType call sites"],"tags":["java","generics","bounded-type-parameter","type-argument"],"backgroundTag":"type-mismatch","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}