|
|
|
@ -7,6 +7,8 @@ |
|
|
|
|
|
|
|
|
|
package com.google.protobuf; |
|
|
|
|
|
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Provides the version of this Protobuf Java runtime, and methods for Protobuf Java gencode to |
|
|
|
|
* validate that versions are compatible. Fields and methods in this class should be only accessed |
|
|
|
@ -29,6 +31,31 @@ public final class RuntimeVersion { |
|
|
|
|
public static final String SUFFIX = "-dev"; |
|
|
|
|
private static final String VERSION_STRING = versionString(MAJOR, MINOR, PATCH, SUFFIX); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Validates that the gencode is in the same domain as the runtime. |
|
|
|
|
* |
|
|
|
|
* <p>This method will be directly called by the google-internal gencode to verify no cross-domain |
|
|
|
|
* usages. |
|
|
|
|
* |
|
|
|
|
* @param gencodeDomain the domain where Protobuf Java code was generated. |
|
|
|
|
* @throws ProtobufRuntimeVersionException if gencodeDomain is not the same as DOMAIN. |
|
|
|
|
*/ |
|
|
|
|
public static void validateProtobufGencodeDomain(RuntimeDomain gencodeDomain) { |
|
|
|
|
// Check the environmental variable, and temporarily disable validation if it's set to true.
|
|
|
|
|
String disableFlag = java.lang.System.getenv("TEMORARILY_DISABLE_PROTOBUF_VERSION_CHECK"); |
|
|
|
|
if ((disableFlag != null && disableFlag.equals("true"))) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (gencodeDomain != DOMAIN) { |
|
|
|
|
throw new ProtobufRuntimeVersionException( |
|
|
|
|
String.format( |
|
|
|
|
"Mismatched Protobuf Gencode/Runtime domains: gencode %s, runtime %s. Cross-domain" |
|
|
|
|
+ " usage of Protobuf is not supported.", |
|
|
|
|
gencodeDomain, DOMAIN)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Validates that the gencode version is compatible with this runtime version according to |
|
|
|
|
* https://protobuf.dev/support/cross-version-runtime-guarantee/.
|
|
|
|
@ -37,7 +64,7 @@ public final class RuntimeVersion { |
|
|
|
|
* |
|
|
|
|
* <p>This method is only for Protobuf Java gencode; do not call it elsewhere. |
|
|
|
|
* |
|
|
|
|
* @param domain the domain where Protobuf Java code was generated. Currently ignored. |
|
|
|
|
* @param domain the domain where Protobuf Java code was generated. |
|
|
|
|
* @param major the major version of Protobuf Java gencode. |
|
|
|
|
* @param minor the minor version of Protobuf Java gencode. |
|
|
|
|
* @param patch the micro/patch version of Protobuf Java gencode. |
|
|
|
@ -47,18 +74,14 @@ public final class RuntimeVersion { |
|
|
|
|
public static void validateProtobufGencodeVersion( |
|
|
|
|
RuntimeDomain domain, int major, int minor, int patch, String suffix) { |
|
|
|
|
|
|
|
|
|
// Check the environmental variable, and temporarily disable poison pills if it's set to true.
|
|
|
|
|
String disableFlag = java.lang.System.getenv("TEMORARILY_DISABLE_PROTOBUF_VERSION_CHECK"); |
|
|
|
|
if (disableFlag != null && disableFlag.equals("true")) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check that version numbers are valid.
|
|
|
|
|
if (major < 0 || minor < 0 || patch < 0) { |
|
|
|
|
throw new ProtobufRuntimeVersionException( |
|
|
|
|
"Invalid gencode version: " + versionString(major, minor, patch, suffix)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validateProtobufGencodeDomain(domain); |
|
|
|
|
|
|
|
|
|
String gencodeVersionString = versionString(major, minor, patch, suffix); |
|
|
|
|
// Check that runtime major version is the same as the gencode major version.
|
|
|
|
|
if (major != MAJOR) { |
|
|
|
|