Review a generated decoder adapter

from Type erasure
Java 25 LTS advanced 6 min 5 issues to find

Review this generated adapter before it processes external payloads.

Invoke one allowlisted decoder with an explicit input and complete output type, preserve useful failures, and reuse validated reflection metadata and stateless decoder instances.

Java
import java.lang.reflect.Method;
import java.util.List;

public class GeneratedDecoder {
    @SuppressWarnings("unchecked")
    static List<String> decodeNames(
            String className, String methodName, Object input) {
        try {
            Class<?> type = Class.forName(className);
            Object codec = type.getDeclaredConstructor().newInstance();
            Method method = type.getDeclaredMethod(methodName, input.getClass());
            method.setAccessible(true);
            Object result = method.invoke(codec, input);
            return (List<String>) result;
        } catch (Exception error) {
            return null;
        }
    }
}

generated code is illustrative, not from any one model

Open in playground
Report an error