apache/shenyu · error · ShenyuException

build json response message is error, newBuilder method is…

Error message

build json response message is error, newBuilder method is null

What it means

JsonServerCallListener.onMessage converts incoming protobuf DynamicMessage to JSON and back. It reflectively calls newBuilder() on the message type to obtain a Builder; the guard checks the builder is null afterwards and throws ShenyuException. In practice the reflective invokeStaticMethod throws (caught by the outer catch) or the type has no newBuilder, so JSON translation of the gRPC message fails and the call is aborted with Status.INTERNAL.

Solutions

  1. Verify the proxied service uses protobuf-generated Message classes with a static newBuilder()
  2. Align protobuf/grpc versions between gateway and backend service
  3. Check the wrapped Status.INTERNAL description/logs for the underlying reflection exception
  4. Regenerate stubs from the correct .proto files if gencode mismatched
Defensive patterns

Strategy: try-catch

Validate before calling

if (!Message.class.isAssignableFrom(requestType)
        || requestType.getMethod("newBuilder") == null) {
    throw new IllegalStateException(requestType + " is not a protobuf-generated message");
}

Try / catch

try { jsonListener.onMessage(message); }
catch (StatusRuntimeException e) {
    log.error("json transcoding failed: {}", e.getStatus().getDescription());
}

Prevention

When it happens

Trigger: A gRPC request/response message whose class does not expose a static newBuilder() method (non-Message types, proto3 gencode mismatches, or classes not generated by protoc), during json-mode gRPC proxying.

Common situations: Gateway json-transcoding a service whose proto classes were compiled with an incompatible protobuf version; messages not actually protobuf-generated classes; grpc version upgrades changing reflection behavior.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/95011ed1abcf3242. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-client/shenyu-client-grpc/src/main/java/org/apache/shenyu/client/grpc/json/JsonServerCallListener.java:70

    }

    @Override
    protected Listener<R> delegate() {
        return delegate;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onMessage(final R message) {
        Message.Builder builder;
        Class<?> t = JsonServerServiceInterceptor.getRequestClazzMap().get(call.getMethodDescriptor().getFullMethodName());
        try {
            builder = (Message.Builder) ReflectUtils.invokeStaticMethod(t, "newBuilder");

            String reqData = JsonMessage.getDataFromDynamicMessage((DynamicMessage) message);
            JsonFormat.parser().ignoringUnknownFields().merge(reqData, builder);
            if (Objects.isNull(builder)) {
                throw new ShenyuException("build json response message is error, newBuilder method is null");
            }

            delegate.onMessage((R) builder.build());
        } catch (Exception e) {
            throw Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException();
        }
    }

    @Override
    public void onHalfClose() {
        super.onHalfClose();
    }

    @Override
    public void onCancel() {
        super.onCancel();
    }

View on GitHub (pinned to 567142e072)