alibaba/arthas · error · RuntimeException
create view instance failure, viewClass:{}
Error message
create view instance failure, viewClass:{} What it means
GrpcResultViewResolver.registerView(Class<? extends GrpcResultView> viewClass) throws RuntimeException when viewClass.newInstance() fails. The method instantiates the view reflectively; any exception from the constructor (access, abstract class, missing no-arg constructor, constructor throws) is wrapped and rethrown.
Source
Thrown at labs/arthas-grpc-web-proxy/src/main/java/com/taobao/arthas/grpcweb/grpc/view/GrpcResultViewResolver.java:112
//TODO 检查model的type是否重复,避免复制代码带来的bug
this.resultViewMap.put(modelClass, view);
return this;
}
public GrpcResultViewResolver registerView(GrpcResultView view) {
Class modelClass = getModelClass(view);
if (modelClass == null) {
throw new NullPointerException("model class is null");
}
return this.registerView(modelClass, view);
}
public void registerView(Class<? extends GrpcResultView> viewClass) {
GrpcResultView view = null;
try {
view = viewClass.newInstance();
} catch (Throwable e) {
throw new RuntimeException("create view instance failure, viewClass:" + viewClass, e);
}
this.registerView(view);
}
/**
* Get model class of result view
*
* @return
*/
public static <V extends GrpcResultView> Class getModelClass(V view) {
//类反射获取子类的draw方法第二个参数的ResultModel具体类型
Class<? extends GrpcResultView> viewClass = view.getClass();
Method[] declaredMethods = viewClass.getDeclaredMethods();
for (int i = 0; i < declaredMethods.length; i++) {
Method method = declaredMethods[i];
if (method.getName().equals("draw")) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 2View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Ensure the view class is concrete, public, and has a public no-arg constructor.
- Move any failing initialization logic out of the constructor into an init method.
- If the class legitimately needs arguments, instantiate it yourself and use the registerView(view) overload instead.
- Under JPMS, add 'opens' for the package containing the view class to permit reflective access.
Example fix
// before: view class has no no-arg constructor
public class MyView implements GrpcResultView {
public MyView(Config cfg) { ... } // only ctor
}
resolver.registerView(MyView.class); // throws 'create view instance failure'
// after: add no-arg constructor, or pass an instance
public class MyView implements GrpcResultView {
public MyView() { this(Config.DEFAULT); }
public MyView(Config cfg) { ... }
}
resolver.registerView(MyView.class);
// or:
resolver.registerView(new MyView(myConfig)); Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate the class is instantiable
int mods = viewClass.getModifiers();
if (Modifier.isAbstract(mods) || Modifier.isInterface(mods)
|| viewClass.getDeclaredConstructor() == null) {
throw new IllegalArgumentException("View class must be concrete with a no-arg ctor: " + viewClass);
}
resolver.registerView(viewClass); Type guard
import java.lang.reflect.Modifier;
public static boolean isInstantiableViewClass(Class<?> cls) {
int m = cls.getModifiers();
if (Modifier.isAbstract(m) || Modifier.isInterface(m)) return false;
try { cls.getDeclaredConstructor(); return true; }
catch (NoSuchMethodException e) { return false; }
} Try / catch
try {
resolver.registerView(viewClass);
} catch (RuntimeException e) {
if (e.getMessage().contains("create view instance failure")) {
// instantiate manually and use the instance overload
GrpcResultView view = viewClass.getDeclaredConstructor().newInstance();
resolver.registerView(view);
} else { throw e; }
} Prevention
- Ensure view classes are concrete, public, and have a public no-arg constructor.
- Prefer instantiating views explicitly and using registerView(view) over class-based registration.
When it happens
Trigger: Registering a view class by Class object where the class is abstract, an interface, lacks a public no-arg constructor, is non-public, or its constructor throws an exception during instantiation.
Common situations: Registering an abstract base view class by mistake; a view class with only a parameterized constructor (no default); a view constructor that performs initialization that fails (e.g. loads a resource that's missing); a non-public class in a package that restricts reflective access under Java module system.
Related errors
- model class is null
- Couldn't find rpcmethod: {}
- Source is not an array: {}
- AllServerStart must be initialized before!
- Cannot write to standard output when {}
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/093fa4b97659725c.
Report an issue: GitHub.