From 7cc5293def152627b37ff35c35cb852cb25d8c2f Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 1 May 2026 10:46:00 -0700 Subject: [PATCH 1/2] compiler: Avoid compile error on weird proto file names This only matters when `@generated=javax` is used, so it shouldn't matter much. It isn't guaranteed that javac will interpret the file as UTF-8, but it is exceedingly common, and it doesn't seem too much to ask if you are using weird file names. --- compiler/src/java_plugin/cpp/java_generator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index a81d54791b4..f8a32b8fcdf 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1206,7 +1207,7 @@ static void PrintService(const ServiceDescriptor* service, bool disable_version, GeneratedAnnotation generated_annotation) { (*vars)["service_name"] = service->name(); - (*vars)["file_name"] = service->file()->name(); + (*vars)["file_name"] = absl::Utf8SafeCEscape(service->file()->name()); (*vars)["service_class_name"] = ServiceClassName(service); (*vars)["grpc_version"] = ""; #ifdef GRPC_VERSION From 3a48e4050696af1d146e387988d26ef568388764 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 6 May 2026 10:16:36 -0700 Subject: [PATCH 2/2] Fix Bazel build --- MODULE.bazel | 1 + compiler/BUILD.bazel | 1 + compiler/src/java_plugin/cpp/java_generator.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 9b10b1e3c36..42c3ed23e03 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -47,6 +47,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [ ] # GRPC_DEPS_END +bazel_dep(name = "abseil-cpp", version = "20250512.1") bazel_dep(name = "bazel_jar_jar", version = "0.1.11.bcr.1") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis") diff --git a/compiler/BUILD.bazel b/compiler/BUILD.bazel index e8a0571e134..a9ffe77a55a 100644 --- a/compiler/BUILD.bazel +++ b/compiler/BUILD.bazel @@ -13,6 +13,7 @@ cc_binary( ], visibility = ["//visibility:public"], deps = [ + "@abseil-cpp//absl/strings", "@com_google_protobuf//:protoc_lib", ], ) diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index f8a32b8fcdf..d0f8cdd13d5 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include "absl/strings/escaping.h" #include #include #include