{"record":{"id":"119a540b4a8dd15a","repo":"apple/pkl","slug":"s-class-is-not-a-valid-type-argument-did-you-m","errorCode":null,"errorMessage":"`%s.class` is not a valid type argument. Did you mean `%s.class`?","messagePattern":"`(.+?)\\.class` is not a valid type argument\\. Did you mean `(.+?)\\.class`\\?","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pkl-config-java/src/main/java/org/pkl/config/java/mapper/Types.java","lineNumber":49,"sourceCode":"\n  public static ParameterizedType parameterizedType(Class<?> rawType, Type... typeArguments) {\n    var typeParamsCount = rawType.getTypeParameters().length;\n    if (typeParamsCount == 0) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Cannot parameterize `%s` because it does not have any type parameters.\",\n              rawType.getTypeName()));\n    }\n    if (typeArguments.length != typeParamsCount) {\n      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","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-config-java/src/main/java/org/pkl/config/java/mapper/Types.java#L31-L67","documentation":"Java generics cannot use primitives as type arguments (List<int> is illegal). When parameterizedType() sees a primitive Class among the type arguments, it throws and suggests the corresponding wrapper class from Reflection.toWrapperType.","triggerScenarios":"parameterizedType(List.class, int.class), parameterizedType(Map.class, String.class, double.class) — any arg where clazz.isPrimitive() is true.","commonSituations":"Mapping Pkl Int to int.class instead of Integer.class, or Float/Boolean similarly; auto-completed .class literals defaulting to primitives.","solutions":["Replace the primitive .class literal with its wrapper: Integer.class, Long.class, Double.class, Boolean.class, etc.","Use Pkl's boxed types for numeric Pkl properties.","Scan your typeArguments array for isPrimitive() before calling."],"exampleFix":"// before\nTypes.parameterizedType(List.class, int.class);\n// after\nTypes.parameterizedType(List.class, Integer.class);","handlingStrategy":"validation","validationCode":"for (Type a : args) if (a instanceof Class<?> c && c.isPrimitive()) throw new IllegalArgumentException(\"use wrapper for \" + c);","typeGuard":"static boolean isBoxed(Type t) { return !(t instanceof Class<?> c && c.isPrimitive()); }","tryCatchPattern":"try { Types.parameterizedType(raw, args); } catch (IllegalArgumentException e) { /* switch to wrapper classes */ }","preventionTips":["Always use Integer/Long/Double/Boolean.class as type arguments","Centralize type-argument construction so primitive literals cannot sneak in"],"tags":["java","generics","primitive","type-argument"],"backgroundTag":"invalid-argument-value","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"}