|
|
|
@ -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 |
|
|
|
@ -36,6 +38,7 @@ public final class RuntimeVersion { |
|
|
|
|
public static final String SUFFIX = OSS_SUFFIX; |
|
|
|
|
|
|
|
|
|
private static final String VERSION_STRING = versionString(MAJOR, MINOR, PATCH, SUFFIX); |
|
|
|
|
private static final Logger logger = Logger.getLogger(RuntimeVersion.class.getName()); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Validates that the gencode version is compatible with this runtime version according to |
|
|
|
@ -83,11 +86,20 @@ public final class RuntimeVersion { |
|
|
|
|
|
|
|
|
|
// Check that runtime major version is the same as the gencode major version.
|
|
|
|
|
if (major != MAJOR) { |
|
|
|
|
throw new ProtobufRuntimeVersionException( |
|
|
|
|
String.format( |
|
|
|
|
"Detected mismatched Protobuf Gencode/Runtime major versions when loading %s: gencode" |
|
|
|
|
+ " %s, runtime %s. Same major version is required.", |
|
|
|
|
location, gencodeVersionString, VERSION_STRING)); |
|
|
|
|
if (major == MAJOR - 1) { |
|
|
|
|
logger.warning( |
|
|
|
|
String.format( |
|
|
|
|
" Protobuf gencode version %s is exactly one major version older than the runtime" |
|
|
|
|
+ " version %s at %s. Please update the gencode to avoid compatibility" |
|
|
|
|
+ " violations in the next runtime release.", |
|
|
|
|
gencodeVersionString, VERSION_STRING, location)); |
|
|
|
|
} else { |
|
|
|
|
throw new ProtobufRuntimeVersionException( |
|
|
|
|
String.format( |
|
|
|
|
"Detected mismatched Protobuf Gencode/Runtime major versions when loading %s:" |
|
|
|
|
+ " gencode %s, runtime %s. Same major version is required.", |
|
|
|
|
location, gencodeVersionString, VERSION_STRING)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check that runtime version is newer than the gencode version.
|
|
|
|
@ -97,6 +109,12 @@ public final class RuntimeVersion { |
|
|
|
|
"Detected incompatible Protobuf Gencode/Runtime versions when loading %s: gencode %s," |
|
|
|
|
+ " runtime %s. Runtime version cannot be older than the linked gencode version.", |
|
|
|
|
location, gencodeVersionString, VERSION_STRING)); |
|
|
|
|
} else if (MINOR > minor || PATCH > patch) { |
|
|
|
|
logger.warning( |
|
|
|
|
String.format( |
|
|
|
|
" Protobuf gencode version %s is older than the runtime version %s at %s. Please" |
|
|
|
|
+ " avoid checked-in Protobuf gencode that can be obsolete.", |
|
|
|
|
gencodeVersionString, VERSION_STRING, location)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check that runtime version suffix is the same as the gencode version suffix.
|
|
|
|
|