Skip to content

Commit 3ce5838

Browse files
Change back to using String instead of Class as the argument on the Poison Pill.
The reason to change this back is that one purpose of this method to provide a good message when e.g. someone tries to use 4.33.0 gencode against 4.30 runtime. The 4.30 runtime only has the `String` argument method, so by having new gencode try to call the `Class` one it will result in ABI behavior of a NoSuchMethodError instead of getting the clean message when that 'bad direction skew' happens. This partial-rollback tries to retain the benefit of avoiding the small cost of the .class.getName() call by having new gencode simply emit the name as a string literal like `"MyMessageProto"` instead of `MyMessageProto.class.getName()` when calling the poison pill. Because we didn't do any open source releases with this change quite yet, we can remove the `Class` overload here instead of it having to linger forever. PiperOrigin-RevId: 813433985
1 parent 3d94d83 commit 3ce5838

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

java/core/src/main/java/com/google/protobuf/RuntimeVersion.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,16 @@ public enum RuntimeDomain {
6565
* @param patch the micro/patch version of Protobuf Java gencode.
6666
* @param suffix the version suffix e.g. "-rc2", "-dev", etc.
6767
* @param location the debugging location e.g. generated Java class to put in the error messages.
68-
* @deprecated Use other overload.
6968
* @throws ProtobufRuntimeVersionException if versions are incompatible.
7069
*/
71-
@Deprecated
7270
public static void validateProtobufGencodeVersion(
7371
RuntimeDomain domain, int major, int minor, int patch, String suffix, String location) {
7472
validateProtobufGencodeVersionImpl(domain, major, minor, patch, suffix, location);
7573
}
7674

77-
/**
78-
* Validates that the gencode version is compatible with this runtime version according to
79-
* https://protobuf.dev/support/cross-version-runtime-guarantee/.
80-
*
81-
* <p>This method is currently only used by Protobuf Java **full version** gencode. Do not call it
82-
* elsewhere.
83-
*
84-
* @param domain the domain where Protobuf Java code was generated.
85-
* @param major the major version of Protobuf Java gencode.
86-
* @param minor the minor version of Protobuf Java gencode.
87-
* @param patch the micro/patch version of Protobuf Java gencode.
88-
* @param suffix the version suffix e.g. "-rc2", "-dev", etc.
89-
* @param location the debugging location e.g. generated Java class to put in the error messages.
90-
* @throws ProtobufRuntimeVersionException if versions are incompatible.
91-
*/
92-
public static void validateProtobufGencodeVersion(
93-
RuntimeDomain domain, int major, int minor, int patch, String suffix, Class<?> location) {
94-
validateProtobufGencodeVersionImpl(domain, major, minor, patch, suffix, location);
95-
}
96-
9775
/** The actual implementation of version validation. */
9876
private static void validateProtobufGencodeVersionImpl(
99-
RuntimeDomain domain, int major, int minor, int patch, String suffix, Object location) {
77+
RuntimeDomain domain, int major, int minor, int patch, String suffix, String location) {
10078
if (checkDisabled()) {
10179
return;
10280
}

src/google/protobuf/compiler/java/helpers.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime,
102102
" $minor$,\n"
103103
" $patch$,\n"
104104
" $suffix$,\n"
105-
" $location$);\n",
106-
"domain", oss_runtime ? "PUBLIC" : "GOOGLE_INTERNAL", "major",
107-
absl::StrCat("/* major= */ ", version.major()), "minor",
108-
absl::StrCat("/* minor= */ ", version.minor()), "patch",
109-
absl::StrCat("/* patch= */ ", version.patch()), "suffix",
110-
absl::StrCat("/* suffix= */ \"", version.suffix(), "\""), "location",
111-
absl::StrCat(java_class_name, ".class"));
105+
" \"$location$\");\n",
106+
"domain", oss_runtime ? "PUBLIC" : "GOOGLE_INTERNAL", //
107+
"major", absl::StrCat("/* major= */ ", version.major()), //
108+
"minor", absl::StrCat("/* minor= */ ", version.minor()), //
109+
"patch", absl::StrCat("/* patch= */ ", version.patch()), //
110+
"suffix", absl::StrCat("/* suffix= */ \"", version.suffix(), "\""), //
111+
"location", java_class_name); //
112112
}
113113

114114
std::string UnderscoresToCamelCase(absl::string_view input,

0 commit comments

Comments
 (0)