apache/maven · error · IllegalArgumentException

Cannot convert: "%s" to: %s

Error message

Cannot convert: "%s" to: %s

What it means

Thrown by Sisu's Plexus XML bean converter when a configuration value that starts with '<' cannot be parsed as XML and converted into the requested role type (TypeLiteral). The converter only attempts XML parsing for values whose trimmed form looks like markup; any parser or conversion failure inside that path (malformed XML, unknown bean property, failed instantiation) is rethrown as an IllegalArgumentException wrapping the original cause.

Source

Thrown at compat/maven-embedder/src/main/java/org/eclipse/sisu/plexus/PlexusXmlBeanConverter.java:93

    PlexusXmlBeanConverter(final Injector injector) {
        typeConverterBindings = injector.getTypeConverterBindings();
    }

    // ----------------------------------------------------------------------
    // Public methods
    // ----------------------------------------------------------------------

    @SuppressWarnings({"unchecked", "rawtypes"})
    public Object convert(final TypeLiteral role, final String value) {
        if (value.trim().startsWith("<")) {
            try {
                final MXParser parser = new MXParser();
                parser.setInput(new StringReader(value));
                parser.nextTag();

                return parse(parser, role);
            } catch (final Exception e) {
                throw new IllegalArgumentException(String.format(CONVERSION_ERROR, value, role), e);
            }
        }

        return convertText(value, role);
    }

    // ----------------------------------------------------------------------
    // Implementation methods
    // ----------------------------------------------------------------------

    /**
     * Parses a sequence of XML elements and converts them to the given target type.
     *
     * @param parser The XML parser
     * @param toType The target type
     * @return Converted instance of the target type
     */
    private Object parse(final MXParser parser, final TypeLiteral<?> toType) throws Exception {

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Read the caused-by chain: the nested exception holds the real failure (XmlPullParserException, 'Unknown bean property', 'Cannot create instance')
  2. Validate the inline XML fragment is well-formed: matching tags, no stray characters before the first '<'
  3. Check every element name against the target bean's writable properties; element names are camelized (max-retries -> maxRetries)
  4. Ensure any class named via implementation= or a nested <implementation> element has a public no-arg constructor
  5. If the value is not meant to be XML, remove the leading '<' so the converter uses the plain-text path

Example fix

// before: plexus.xml - mismatched tag inside inline XML value
<component>
  <role>com.example.Server</role>
  <implementation>com.example.Server</implementation>
  <configuration>
    <hosts><host>alpha</hosts></hosts>
  </configuration>
</component>

// after: well-formed XML that maps onto the Server bean
<component>
  <role>com.example.Server</role>
  <implementation>com.example.Server</implementation>
  <configuration>
    <hosts><host>alpha</host></hosts>
  </configuration>
</component>
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check: only values that look like XML go down the XML path
String v = value == null ? "" : value.trim();
if (v.startsWith("<")) {
    try {
        MXParser p = new MXParser();
        p.setInput(new StringReader(v));
        p.nextTag(); // throws on malformed markup before the converter runs
    } catch (Exception e) {
        throw new IllegalArgumentException("Malformed inline XML config", e);
    }
}
Object converted = converter.convert(role, value);

Try / catch

try {
    Object v = converter.convert(role, value);
} catch (IllegalArgumentException e) {
    // the real reason is nested: XmlPullParserException / unknown property / instantiation
    Throwable root = e.getCause() != null ? e.getCause() : e;
    log.warn("Sisu conversion failed for {}: {}", role, root.getMessage());
}

Prevention

When it happens

Trigger: Calling PlexusXmlBeanConverter.convert(TypeLiteral, String) directly or via Sisu/Plexus configuration injection, with a value whose trimmed form starts with '<' but is malformed XML, references unknown elements, or targets a type/implementation that cannot accept the parsed content.

Common situations: Hand-edited plexus.xml/components.xml with mismatched tags or wrong element names inside <configuration>; component upgrades that renamed bean properties so previously valid inline XML no longer maps; embedding Sisu with custom bean types that lack a default constructor.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/ddb68958f9b315b2. Report an issue: GitHub.