{"record":{"id":"054f3b0d4cf19f1a","repo":"apple/pkl","slug":"type-mappings-are-not-supported-for-array-types","errorCode":null,"errorMessage":"Type mappings are not supported for array types.","messagePattern":"Type mappings are not supported for array types\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pkl-config-java/src/main/java/org/pkl/config/java/mapper/TypeMapping.java","lineNumber":48,"sourceCode":"public final class TypeMapping<S, T extends S> {\n  public final Class<S> requestedType;\n  public final Class<T> implementationType;\n\n  private TypeMapping(Class<S> requestedType, Class<T> implementationType) {\n    if (Modifier.isAbstract(implementationType.getModifiers())) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"`implementationType` must not be abstract, but `%s` is.\",\n              implementationType.getTypeName()));\n    }\n    if (!requestedType.isAssignableFrom(implementationType)) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"`implementationType` must be assignable to `requestedType`, but `%s` is not assignable to `%s`.\",\n              implementationType.getTypeName(), requestedType.getTypeName()));\n    }\n    if (requestedType.isArray() || implementationType.isArray()) {\n      throw new IllegalArgumentException(\"Type mappings are not supported for array types.\");\n    }\n    this.requestedType = requestedType;\n    this.implementationType = implementationType;\n  }\n\n  public static <S, T extends S> TypeMapping<S, T> of(\n      Class<S> requestedType, Class<T> implementationType) {\n    return new TypeMapping<>(requestedType, implementationType);\n  }\n\n  @Override\n  public boolean equals(@Nullable Object obj) {\n    if (this == obj) return true;\n    if (!(obj instanceof TypeMapping<?, ?> other)) return false;\n    return requestedType == other.requestedType && implementationType == other.implementationType;\n  }\n\n  @Override","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-config-java/src/main/java/org/pkl/config/java/mapper/TypeMapping.java#L30-L66","documentation":"Type mappings are only defined for class types; when either requestedType or implementationType is an array class (Class.isArray()), the constructor refuses. Array types have no type-name/parameterization semantics the mapper can handle.","triggerScenarios":"TypeMapping.of(String[].class, ...) or TypeMapping.of(X.class, Y[].class) — either Class object represents an array.","commonSituations":"Trying to map Pkl lists/sequences to Java arrays; mapping Pkl `List<Int>` to int[].class instead of using the collection converters.","solutions":["Map to a collection type (List, Set) instead of an array.","Use the built-in collection converters (listOf, etc.) rather than a custom array mapping.","Post-process a mapped List into an array yourself after mapping."],"exampleFix":"// before\nTypeMapping.of(List.class, int[].class);\n// after\nTypeMapping.of(List.class, ArrayList.class);","handlingStrategy":"validation","validationCode":"if (req.isArray() || impl.isArray()) throw new IllegalArgumentException(\"use collection types, not arrays\");","typeGuard":"static boolean isNonArrayType(Class<?> c) { return !c.isArray(); }","tryCatchPattern":"try { TypeMapping.of(req, impl); } catch (IllegalArgumentException e) { /* fall back to List-based mapping */ }","preventionTips":["Model Pkl lists as java.util.List implementations, never arrays","Convert List results to arrays yourself after mapping if arrays are needed"],"tags":["java","type-mapping","array","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}