junit-team/junit5 · warning · UnsupportedOperationException

Invoke convert(String, Class<?>, ClassLoader) instead

Error message

Invoke convert(String, Class<?>, ClassLoader) instead

What it means

Internal UnsupportedOperationException raised by StringToClassConverter's 2-argument convert(String, Class) overload. Loading a Class requires a ClassLoader, so only the 3-argument convert(String, Class, ClassLoader) is supported. ConversionSupport always routes through the 3-arg overload (line 127), so this is not reachable through normal ConversionSupport usage.

Solutions

  1. Do not call the 2-arg convert overload directly on StringToClassConverter
  2. Always go through ConversionSupport.convert(source, type, classLoader), which routes to the correct overload
  3. Treat StringToObjectConverter implementations as internal API and never instantiate or invoke them directly
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Directly invoking StringToClassConverter.convert(source, Class.class) on the 2-arg overload - only possible from reflective/internal code that bypasses ConversionSupport, or from a custom StringToObjectConverter misrouting Class.class targets.

Common situations: Not encountered by end users; would indicate a custom converter implementation calling the unsupported 2-arg overload, or reflection-based abuse of internal package classes.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/bb79997430f65d37. Report an issue: GitHub.

Appendix: source

Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/StringToClassConverter.java:24

 * accompanies this distribution and is available at
 *
 * https://www.eclipse.org/legal/epl-v20.html
 */

package org.junit.platform.commons.support.conversion;

import org.junit.platform.commons.support.ReflectionSupport;

class StringToClassConverter implements StringToObjectConverter {

	@Override
	public boolean canConvertTo(Class<?> targetType) {
		return targetType == Class.class;
	}

	@Override
	public Object convert(String source, Class<?> targetType) throws Exception {
		throw new UnsupportedOperationException("Invoke convert(String, Class<?>, ClassLoader) instead");
	}

	@Override
	public Class<?> convert(String className, Class<?> targetType, ClassLoader classLoader) throws Exception {
		// @formatter:off
		return ReflectionSupport.tryToLoadClass(className, classLoader)
				.getNonNullOrThrow(cause -> new ConversionException(
						"Failed to convert String \"" + className + "\" to type java.lang.Class", cause));
		// @formatter:on
	}

}

View on GitHub (pinned to f070c699a0)