apple/pkl · error · KotlinCodeGeneratorException

Standard library class

Error message

Standard library class `${pClass.qualifiedName}` is not supported by Kotlin code generator. If you think this is an omission, please let us know.

What it means

When a referenced class belongs to the Pkl standard library but has no hardcoded Kotlin mapping in toKotlinPoetName (only known ones like PClassInfo.Regex or Version are mapped), the generator throws KotlinCodeGeneratorException and invites a feature request.

Solutions

  1. Re-type the property to a mapped stdlib class or one of your own classes.
  2. Check which stdlib classes your pkl-codegen-kotlin version supports; upgrade the codegen tooling.
  3. File an issue with the pkl project to add a mapping for that stdlib class.

Example fix

// before (Pkl)
prop: pkl.base.UnmappedClass
// after
prop: String
Defensive patterns

Strategy: validation

Validate before calling

if (pClass.info.isStandardLibraryClass && pClass.info !in SUPPORTED_STD_LIB_CLASSES) {
  throw IllegalArgumentException("Stdlib class ${pClass.qualifiedName} unmapped for Kotlin codegen")
}

Type guard

fun isSupportedStdlibClass(info: PClassInfo): Boolean =
  !info.isStandardLibraryClass ||
  info in setOf(PClassInfo.Regex, PClassInfo.Version /* ...known mappings */)

Try / catch

try {
  generator.generate(module)
} catch (e: KotlinCodeGeneratorException) {
  if (e.message?.contains("Standard library class") == true) {
    logger.warn("Re-type or upgrade codegen for: ${e.message}")
  } else throw e
}

Prevention

When it happens

Trigger: A property in a generated module is typed with an unmapped stdlib class (e.g. lesser-used pkl.base classes) while running Kotlin codegen.

Common situations: Using newer or niche stdlib classes that postdate the generator's PClassInfo mapping table.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/72d2ad690b21d1ef. Report an issue: GitHub.

Appendix: source

Thrown at pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt:706

          PClassInfo.Set ->
            SET.parameterizedBy(
              if (typeArguments.isEmpty()) ANY_NULL else typeArguments[0].toKotlinPoetName()
            )
          PClassInfo.Map,
          PClassInfo.Mapping ->
            MAP.parameterizedBy(
              if (typeArguments.isEmpty()) ANY_NULL else typeArguments[0].toKotlinPoetName(),
              if (typeArguments.isEmpty()) ANY_NULL else typeArguments[1].toKotlinPoetName(),
            )
          PClassInfo.Module -> PMODULE
          PClassInfo.Class -> PCLASS
          PClassInfo.Regex -> REGEX
          PClassInfo.Version -> VERSION
          else ->
            when {
              !classInfo.isStandardLibraryClass -> pClass.toKotlinPoetName()
              else ->
                throw KotlinCodeGeneratorException(
                  "Standard library class `${pClass.qualifiedName}` is not supported by Kotlin code generator. " +
                    "If you think this is an omission, please let us know."
                )
            }
        }
      }
      is PType.Nullable -> baseType.toKotlinPoetName().copy(nullable = true)
      is PType.Constrained -> baseType.toKotlinPoetName()
      is PType.Alias ->
        when (typeAlias.qualifiedName) {
          "pkl.base#NonNull" -> ANY
          // Not currently generating Kotlin unsigned types
          // because it's not clear if the benefits outweigh the drawbacks:
          // - breaking change
          // - Kotlin unsigned types aren't intended for domain modeling
          // - diverts from Java code generator
          // - doesn't increase safety
          //   - range already checked on Pkl side

View on GitHub (pinned to f3efcbfc9b)