apple/pkl · error · ConversionException

Failed to invoke `javax.inject.Named.value()`.

Error message

Failed to invoke `javax.inject.Named.value()`.

What it means

pkl-config-java maps Pkl objects to Java data objects via constructors. To resolve constructor parameter names, it falls back to the javax.inject @Named annotation when parameter names aren't retained in bytecode. This error is thrown when reflectively invoking the annotation's value() method fails via IllegalAccessException or InvocationTargetException, so the library cannot determine the parameter name.

Source

Thrown at pkl-config-java/src/main/java/org/pkl/config/java/mapper/PObjectToDataObject.java:125

  private static @Nullable String getParameterName(Parameter parameter) {
    if (parameter.isNamePresent()) {
      return parameter.getName();
    }

    Named named = getAnnotation(parameter, Named.class);
    if (named != null) {
      return named.value();
    }

    if (javaxInjectNamedClass != null) {
      assert javaxInjectNamedValueMethod != null;
      var ann = getAnnotation(parameter, javaxInjectNamedClass);
      if (ann != null) {
        try {
          return (String) javaxInjectNamedValueMethod.invoke(ann);
        } catch (IllegalAccessException | InvocationTargetException e) {
          throw new ConversionException("Failed to invoke `javax.inject.Named.value()`.", e);
        }
      }
    }

    return null;
  }

  private static @Nullable <T extends Annotation> T getAnnotation(
      Constructor<?> constructor, Class<T> annotationClass) {
    try {
      return constructor.getAnnotation(annotationClass);
    } catch (IndexOutOfBoundsException e) {
      // workaround for https://bugs.openjdk.java.net/browse/JDK-8025806
      return null;
    }
  }

  private static @Nullable <T extends Annotation> T getAnnotation(

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Compile with -parameters (or keep the source of parameter names, e.g. Maven maven-compiler-plugin <parameters>true</parameters>) so getParameterName never needs the @Named fallback.
  2. Check the classpath for conflicting javax.inject artifacts and use a single, standard version (javax.inject:javax.inject:1 or jakarta.inject equivalent).
  3. Verify module accessibility: if using JPMS, open/exports the package containing the annotation to pkl-config-java.
  4. If caught as a ConversionException, inspect the cause (IllegalAccessException vs InvocationTargetException) to pinpoint the reflective failure.

Example fix

// before: names resolved via fragile reflective annotation fallback
<artifactId>maven-compiler-plugin</artifactId>
<configuration><!-- no --parameters --></configuration>

// after
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
  <parameters>true</parameters>
</configuration>
Defensive patterns

Strategy: validation

Validate before calling

// ensure parameter names are resolvable before converting
boolean namesResolvable(Constructor<?> ctor) {
  for (Parameter p : ctor.getParameters()) {
    if (p.isNamePresent()) continue;
    if (p.getAnnotation(Named.class) != null) continue;
    if (p.getAnnotation(javax.inject.Named.class) != null) continue;
    return false;
  }
  return true;
}

Prevention

When it happens

Trigger: Calling Converter.convert on a Pkl Composite whose target Java class has a constructor parameter annotated with javax.inject.@Named, and Method.invoke on the annotation's value() member throws — e.g. the annotation proxy rejects access, the annotation instance is corrupt, or its value() resolver throws InvocationTargetException (nested initializer failure).

Common situations: Runtime environments with restricted reflection (custom class loaders, modules closing javax.inject package); classpath conflicts where an incompatible/duplicate javax.inject jar provides a broken @Named; annotation-processed code where the annotation target is inconsistent with the compiled bytecode.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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