{"record":{"id":"bb79997430f65d37","repo":"junit-team/junit5","slug":"invoke-convert-string-class-classloader-inst","errorCode":null,"errorMessage":"Invoke convert(String, Class<?>, ClassLoader) instead","messagePattern":"Invoke convert\\(String, Class<\\?>, ClassLoader\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/StringToClassConverter.java","lineNumber":24,"sourceCode":" * accompanies this distribution and is available at\n *\n * https://www.eclipse.org/legal/epl-v20.html\n */\n\npackage org.junit.platform.commons.support.conversion;\n\nimport org.junit.platform.commons.support.ReflectionSupport;\n\nclass StringToClassConverter implements StringToObjectConverter {\n\n\t@Override\n\tpublic boolean canConvertTo(Class<?> targetType) {\n\t\treturn targetType == Class.class;\n\t}\n\n\t@Override\n\tpublic Object convert(String source, Class<?> targetType) throws Exception {\n\t\tthrow new UnsupportedOperationException(\"Invoke convert(String, Class<?>, ClassLoader) instead\");\n\t}\n\n\t@Override\n\tpublic Class<?> convert(String className, Class<?> targetType, ClassLoader classLoader) throws Exception {\n\t\t// @formatter:off\n\t\treturn ReflectionSupport.tryToLoadClass(className, classLoader)\n\t\t\t\t.getNonNullOrThrow(cause -> new ConversionException(\n\t\t\t\t\t\t\"Failed to convert String \\\"\" + className + \"\\\" to type java.lang.Class\", cause));\n\t\t// @formatter:on\n\t}\n\n}\n","sourceCodeStart":6,"sourceCodeEnd":37,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/StringToClassConverter.java#L6-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Do not call the 2-arg convert overload directly on StringToClassConverter","Always go through ConversionSupport.convert(source, type, classLoader), which routes to the correct overload","Treat StringToObjectConverter implementations as internal API and never instantiate or invoke them directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ConversionSupport.convert rather than internal converter classes","Treat StringToObjectConverter implementations as internal API","Never instantiate or directly invoke package-private converter classes"],"tags":["conversion","internal-api","classloader"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}