Binary compatibility shims for GeneratedMessageV3, SingleFieldBuilderV3, RepeatedFieldBuilderV3, and their nested classes to restore binary compatibility with <=v3.x.x generated code built against v3.x.x prior to v4.26.0 breaking release.

3.x.x descriptor.proto generated code is *not* supported with 4.x.x runtime, since this results in an ODR violation with the descriptor.proto built into the 4.x.x runtime. This is expected to result in undefined behavior / failures.

Tested against //java/core:v25_generated_message_test_jar (binary compatibility) and //java/core:v25_generated_message_test_srcjar (source compatibility)

PiperOrigin-RevId: 666329342
This commit is contained in:
Sandy Zhang 2024-08-22 06:46:26 -07:00 коммит произвёл Copybara-Service
Родитель e9140a10ec
Коммит df8a11e266
12 изменённых файлов: 1504 добавлений и 64 удалений

Просмотреть файл

@ -238,13 +238,9 @@ http_archive(
url = "https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz",
)
# Needed as a dependency of @com_google_protobuf_v25.x, which was before
# utf8_range was merged in.
http_archive(
name = "utf8_range",
strip_prefix = "utf8_range-d863bc33e15cba6d873c878dcca9e6fe52b2f8cb",
url = "https://github.com/protocolbuffers/utf8_range/archive/d863bc33e15cba6d873c878dcca9e6fe52b2f8cb.zip",
)
# Needed as a dependency of @com_google_protobuf_v25.0
load("@com_google_protobuf_v25.0//:protobuf_deps.bzl", protobuf_v25_deps="protobuf_deps")
protobuf_v25_deps()
# Needed for testing only
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Просмотреть файл

@ -30,13 +30,10 @@ http_archive(
url = "https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz",
)
# Needed as a dependency of @com_google_protobuf_v25.x, which was before
# utf8_range was merged in.
http_archive(
name = "utf8_range",
strip_prefix = "utf8_range-d863bc33e15cba6d873c878dcca9e6fe52b2f8cb",
url = "https://github.com/protocolbuffers/utf8_range/archive/d863bc33e15cba6d873c878dcca9e6fe52b2f8cb.zip",
)
# Needed as a dependency of @com_google_protobuf_v25.0
load("@com_google_protobuf_v25.0//:protobuf_deps.bzl", protobuf_v25_deps="protobuf_deps")
protobuf_v25_deps()
# Needed for checking breaking changes from the previous release version.
load("//:protobuf_version.bzl", "PROTOBUF_PREVIOUS_RELEASE")

Просмотреть файл

@ -7,6 +7,26 @@ load("//compatibility:runtime_conformance.bzl", "java_runtime_conformance")
# To add more test cases in Java, use java_runtime_conformance as below, and add
# the corresponding http_archive in the WORKSPACE file for the version.
java_library(
name = "v25_test_protos_srcjar",
testonly = True,
srcs = glob([
"v3.25.0/*.srcjar",
]),
visibility = ["//java/core:__pkg__"],
deps = ["//java/core"],
)
java_library(
name = "v25_test_protos_jar",
testonly = True,
srcs = glob([
"v3.25.0/*.srcjar",
]),
visibility = ["//java/core:__pkg__"],
deps = ["@com_google_protobuf_v25.0//java/core"],
)
# main gencode builds with main runtime as a proof of concept.
java_runtime_conformance(
name = "java_conformance_main",

Двоичные данные
compatibility/v3.25.0/generic_test_protos-speed.srcjar Executable file

Двоичный файл не отображается.

Двоичные данные
compatibility/v3.25.0/java_test_protos-speed.srcjar Executable file

Двоичный файл не отображается.

Двоичные данные
compatibility/v3.25.0/lite_test_protos-speed.srcjar Executable file

Двоичный файл не отображается.

Просмотреть файл

@ -590,6 +590,102 @@ junit_tests(
],
)
protobuf_java_library(
name = "v25_test_util_srcjar",
testonly = True,
srcs = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
],
deps = [
":core",
"//compatibility:v25_test_protos_srcjar",
"@maven//:com_google_guava_guava",
"@maven//:junit_junit",
],
)
# Tests source compatibility against v25 gencode jar compiled against current runtime
junit_tests(
name = "v25_core_tests_srcjar",
size = "small",
srcs = glob(
["src/test/java/**/*.java"],
exclude = [
# Depends on test protos or API changes added in v4.x.x (e.g. editions)
"src/test/java/com/google/protobuf/TextFormatTest.java",
"src/test/java/com/google/protobuf/DescriptorsTest.java",
"src/test/java/com/google/protobuf/DebugFormatTest.java",
"src/test/java/com/google/protobuf/CodedOutputStreamTest.java",
"src/test/java/com/google/protobuf/ProtobufToStringOutputTest.java",
# Excluded in core_tests
"src/test/java/com/google/protobuf/DecodeUtf8Test.java",
"src/test/java/com/google/protobuf/IsValidUtf8Test.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
"src/test/java/com/google/protobuf/RuntimeVersionTest.java",
],
),
test_prefix = "v25SrcJar",
deps = [
":core",
":v25_test_util_srcjar",
"//compatibility:v25_test_protos_srcjar",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_core",
],
)
protobuf_java_library(
name = "v25_test_util_jar",
testonly = True,
srcs = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
],
deps = [
":core",
"//compatibility:v25_test_protos_jar",
"@maven//:com_google_guava_guava",
"@maven//:junit_junit",
],
)
# Tests binary compatibility against v25 gencode ja compiled against v25 runtime
junit_tests(
name = "v25_core_tests_jar",
size = "small",
srcs = glob(
["src/test/java/**/*.java"],
exclude = [
# Depends on test protos or API changes added in v4.x.x (e.g. editions)
"src/test/java/com/google/protobuf/TextFormatTest.java",
"src/test/java/com/google/protobuf/DescriptorsTest.java",
"src/test/java/com/google/protobuf/DebugFormatTest.java",
"src/test/java/com/google/protobuf/CodedOutputStreamTest.java",
"src/test/java/com/google/protobuf/ProtobufToStringOutputTest.java",
# Excluded in core_tests
"src/test/java/com/google/protobuf/DecodeUtf8Test.java",
"src/test/java/com/google/protobuf/IsValidUtf8Test.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
"src/test/java/com/google/protobuf/RuntimeVersionTest.java",
],
),
test_prefix = "v25Jar",
deps = [
":core",
":v25_test_util_jar",
"//compatibility:v25_test_protos_jar",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_core",
],
)
pkg_files(
name = "dist_files",
srcs = glob([

Просмотреть файл

@ -884,16 +884,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
Message getDefaultInstanceForType();
/** Check if a singular extension is present. */
<T> boolean hasExtension(ExtensionLite<MessageT, T> extension);
<T> boolean hasExtension(ExtensionLite<? extends MessageT, T> extension);
/** Get the number of elements in a repeated extension. */
<T> int getExtensionCount(ExtensionLite<MessageT, List<T>> extension);
<T> int getExtensionCount(ExtensionLite<? extends MessageT, List<T>> extension);
/** Get the value of an extension. */
<T> T getExtension(ExtensionLite<MessageT, T> extension);
<T> T getExtension(ExtensionLite<? extends MessageT, T> extension);
/** Get one element of a repeated extension. */
<T> T getExtension(ExtensionLite<MessageT, List<T>> extension, int index);
<T> T getExtension(ExtensionLite<? extends MessageT, List<T>> extension, int index);
}
/**
@ -944,7 +944,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
this.extensions = builder.buildExtensions();
}
private void verifyExtensionContainingType(final Extension<MessageT, ?> extension) {
private void verifyExtensionContainingType(final Extension<? extends MessageT, ?> extension) {
if (extension.getDescriptor().getContainingType() != getDescriptorForType()) {
// This can only happen if someone uses unchecked operations.
throw new IllegalArgumentException(
@ -958,7 +958,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Check if a singular extension is present. */
@Override
public final <T> boolean hasExtension(final ExtensionLite<MessageT, T> extensionLite) {
public final <T> boolean hasExtension(
final ExtensionLite<? extends MessageT, T> extensionLite) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -967,7 +968,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Get the number of elements in a repeated extension. */
@Override
public final <T> int getExtensionCount(final ExtensionLite<MessageT, List<T>> extensionLite) {
public final <T> int getExtensionCount(
final ExtensionLite<? extends MessageT, List<T>> extensionLite) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -978,7 +980,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Get the value of an extension. */
@Override
@SuppressWarnings("unchecked")
public final <T> T getExtension(final ExtensionLite<MessageT, T> extensionLite) {
public final <T> T getExtension(final ExtensionLite<? extends MessageT, T> extensionLite) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1001,7 +1003,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
@Override
@SuppressWarnings("unchecked")
public final <T> T getExtension(
final ExtensionLite<MessageT, List<T>> extensionLite, final int index) {
final ExtensionLite<? extends MessageT, List<T>> extensionLite, final int index) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1052,7 +1054,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
private Map.Entry<FieldDescriptor, Object> next;
private final boolean messageSetWireFormat;
private ExtensionWriter(final boolean messageSetWireFormat) {
// TODO: Should be marked private in v5.x.x once GeneratedMessageV3 is removed.
protected ExtensionWriter(final boolean messageSetWireFormat) {
if (iter.hasNext()) {
next = iter.next();
}
@ -1296,7 +1299,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Check if a singular extension is present. */
@Override
public final <T> boolean hasExtension(final ExtensionLite<MessageT, T> extensionLite) {
public final <T> boolean hasExtension(
final ExtensionLite<? extends MessageT, T> extensionLite) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1305,7 +1309,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Get the number of elements in a repeated extension. */
@Override
public final <T> int getExtensionCount(final ExtensionLite<MessageT, List<T>> extensionLite) {
public final <T> int getExtensionCount(
final ExtensionLite<? extends MessageT, List<T>> extensionLite) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1315,7 +1320,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Get the value of an extension. */
@Override
public final <T> T getExtension(final ExtensionLite<MessageT, T> extensionLite) {
public final <T> T getExtension(final ExtensionLite<? extends MessageT, T> extensionLite) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1337,7 +1342,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Get one element of a repeated extension. */
@Override
public final <T> T getExtension(
final ExtensionLite<MessageT, List<T>> extensionLite, final int index) {
final ExtensionLite<? extends MessageT, List<T>> extensionLite, final int index) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1351,7 +1356,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Set the value of an extension. */
public final <T> BuilderT setExtension(
final ExtensionLite<MessageT, T> extensionLite, final T value) {
final ExtensionLite<? extends MessageT, T> extensionLite, final T value) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1364,7 +1369,9 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Set the value of one element of a repeated extension. */
public final <T> BuilderT setExtension(
final ExtensionLite<MessageT, List<T>> extensionLite, final int index, final T value) {
final ExtensionLite<? extends MessageT, List<T>> extensionLite,
final int index,
final T value) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1377,7 +1384,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
/** Append a value to a repeated extension. */
public final <T> BuilderT addExtension(
final ExtensionLite<MessageT, List<T>> extensionLite, final T value) {
final ExtensionLite<? extends MessageT, List<T>> extensionLite, final T value) {
Extension<MessageT, List<T>> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1389,7 +1396,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
}
/** Clear an extension. */
public final <T> BuilderT clearExtension(final ExtensionLite<MessageT, T> extensionLite) {
public final <T> BuilderT clearExtension(
final ExtensionLite<? extends MessageT, T> extensionLite) {
Extension<MessageT, T> extension = checkNotLite(extensionLite);
verifyExtensionContainingType(extension);
@ -1605,7 +1613,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
}
}
protected final void mergeExtensionFields(final ExtendableMessage<?> other) {
// TODO: Should be marked final in v5.x.x once GeneratedMessageV3 is removed.
protected void mergeExtensionFields(final ExtendableMessage<?> other) {
if (other.extensions != null) {
ensureExtensionsIsMutable();
extensions.mergeFrom(other.extensions);
@ -1981,7 +1990,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
* Users should ignore this class. This class provides the implementation with access to the
* fields of a message object using Java reflection.
*/
public static final class FieldAccessorTable {
// TODO: Should be marked final in v5.x.x once GeneratedMessageV3 is removed.
public static class FieldAccessorTable {
/**
* Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable
@ -3172,7 +3182,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial
* Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}.
*/
private static <MessageT extends ExtendableMessage<MessageT>, T>
Extension<MessageT, T> checkNotLite(ExtensionLite<MessageT, T> extension) {
Extension<MessageT, T> checkNotLite(ExtensionLite<? extends MessageT, T> extension) {
if (extension.isLite()) {
throw new IllegalArgumentException("Expected non-lite extension.");
}

Просмотреть файл

@ -7,58 +7,538 @@
package com.google.protobuf;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.OneofDescriptor;
import java.util.List;
/**
* Stub for GeneratedMessageV3 wrapping GeneratedMessage for compatibility with older gencode.
*
* <p>Extends GeneratedMessage.ExtendableMessage instead of GeneratedMessage to allow "multiple
* inheritance" for GeneratedMessageV3.ExtendableMessage subclass.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x in 2025 Q1). Users should update gencode to >= 4.26.x which uses GeneratedMessage
* instead of GeneratedMessageV3.
* (5.x). Users should update gencode to >= 4.26.x which uses GeneratedMessage instead.
*/
@Deprecated
public abstract class GeneratedMessageV3 extends GeneratedMessage {
public abstract class GeneratedMessageV3
extends GeneratedMessage.ExtendableMessage<GeneratedMessageV3> {
private static final long serialVersionUID = 1L;
@Deprecated
protected GeneratedMessageV3() {
super();
}
@Deprecated
protected GeneratedMessageV3(Builder<?> builder) {
super(builder);
}
/* Overrides abstract GeneratedMessage.internalGetFieldAccessorTable().
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.internalGetFieldAccessorTable() instead.
*/
@Deprecated
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
throw new UnsupportedOperationException("Should be overridden in gencode.");
}
/**
* Stub for GeneratedMessageV3.UnusedPrivateParameter for compatibility with older gencode.
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.UnusedPrivateParameter instead.
*/
@Deprecated
protected static final class UnusedPrivateParameter {
static final UnusedPrivateParameter INSTANCE = new UnusedPrivateParameter();
private UnusedPrivateParameter() {}
}
/* Stub for method overridden from old generated code
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.newInstance() instead.
*/
@Deprecated
@SuppressWarnings({"unused"})
protected Object newInstance(UnusedPrivateParameter unused) {
throw new UnsupportedOperationException("This method must be overridden by the subclass.");
}
@Deprecated
protected interface BuilderParent extends AbstractMessage.BuilderParent {}
@Deprecated
protected abstract Message.Builder newBuilderForType(BuilderParent parent);
/* Removed from GeneratedMessage in
* https://github.com/protocolbuffers/protobuf/commit/787447430fc9a69c071393e85a380b664d261ab4
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which no longer uses this method.
*/
@Deprecated
@Override
protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) {
return newBuilderForType(
new BuilderParent() {
@Override
public void markDirty() {
parent.markDirty();
}
});
}
/**
* Stub for GeneratedMessageV3.Builder wrapping GeneratedMessage.Builder for compatibility with
* older gencode.
*
* <p>Extends GeneratedMessage.ExtendableBuilder instead of GeneratedMessage.Builder to allow
* "multiple inheritance" for GeneratedMessageV3.ExtendableBuilder subclass.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses GeneratedMessage.Builder
* instead.
*/
@Deprecated
public abstract static class Builder<BuilderT extends Builder<BuilderT>>
extends GeneratedMessage.ExtendableBuilder<GeneratedMessageV3, BuilderT> {
private BuilderParentImpl meAsParent;
@Deprecated
protected Builder() {
super(null);
}
@Deprecated
protected Builder(BuilderParent builderParent) {
super(builderParent);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.clone() instead. */
@Deprecated
@Override
public BuilderT clone() {
return super.clone();
}
/* Stub for method overridden from old generated code
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.setField() instead. */
@Deprecated
@Override
public BuilderT clear() {
return super.clear();
}
/* Overrides abstract GeneratedMessage.Builder.internalGetFieldAccessorTable().
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.internalGetFieldAccessorTable() instead.
*/
@Deprecated
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
throw new UnsupportedOperationException("Should be overridden in gencode.");
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.setField() instead. */
@Deprecated
@Override
public BuilderT setField(final FieldDescriptor field, final Object value) {
return super.setField(field, value);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.clearField() instead. */
@Deprecated
@Override
public BuilderT clearField(final FieldDescriptor field) {
return super.clearField(field);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.clearOneof() instead. */
@Deprecated
@Override
public BuilderT clearOneof(final OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.setRepeatedField() instead. */
@Deprecated
@Override
public BuilderT setRepeatedField(
final FieldDescriptor field, final int index, final Object value) {
return super.setRepeatedField(field, index, value);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.addRepeatedField() instead. */
@Deprecated
@Override
public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) {
return super.addRepeatedField(field, value);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.setUnknownFields() instead. */
@Deprecated
@Override
public BuilderT setUnknownFields(final UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.Builder.mergeUnknownFields() instead. */
@Deprecated
@Override
public BuilderT mergeUnknownFields(final UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
@Deprecated
private class BuilderParentImpl implements BuilderParent {
@Override
public void markDirty() {
onChanged();
}
}
/* Returns GeneratedMessageV3.Builder.BuilderParent instead of
* GeneratedMessage.Builder.BuilderParent.
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.Builder.getParentForChildren() instead.
*/
@Deprecated
@Override
protected BuilderParent getParentForChildren() {
if (meAsParent == null) {
meAsParent = new BuilderParentImpl();
}
return meAsParent;
}
}
/**
* Stub for GeneratedMessageV3.ExtendableMessageOrBuilder wrapping
* GeneratedMessage.ExtendableMessageOrBuilder for compatibility with older gencode.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableMessageOrBuilder.
*/
@Deprecated
public interface ExtendableMessageOrBuilder<MessageT extends ExtendableMessage<MessageT>>
extends GeneratedMessage.ExtendableMessageOrBuilder<GeneratedMessageV3> {
/* Removed from GeneratedMessage.ExtendableMessageOrBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
<T> boolean hasExtension(GeneratedExtension<MessageT, T> extension);
/* Removed from GeneratedMessage.ExtendableMessageOrBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
<T> int getExtensionCount(GeneratedExtension<MessageT, List<T>> extension);
/* Removed from GeneratedMessage.ExtendableMessageOrBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
<T> T getExtension(GeneratedExtension<MessageT, T> extension);
/* Removed from GeneratedMessage.ExtendableMessageOrBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
<T> T getExtension(GeneratedExtension<MessageT, List<T>> extension, int index);
}
/**
* Stub for GeneratedMessageV3.ExtendableMessage wrapping GeneratedMessage.ExtendableMessage for
* compatibility with older gencode.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableMessage.
*/
@Deprecated
public abstract static class ExtendableMessage<MessageT extends ExtendableMessage<MessageT>>
extends GeneratedMessageV3 // Extends GeneratedMessage.ExtendableMessage via
// GeneratedMessageV3
implements ExtendableMessageOrBuilder<MessageT> {
@Deprecated
protected ExtendableMessage() {
super();
}
@Deprecated
protected ExtendableMessage(ExtendableBuilder<MessageT, ?> builder) {
super(builder);
}
/* Removed from GeneratedMessage.ExtendableMessage in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> boolean hasExtension(final GeneratedExtension<MessageT, T> extension) {
return hasExtension((ExtensionLite<MessageT, T>) extension);
}
/* Removed from GeneratedMessage.ExtendableMessage in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> int getExtensionCount(final GeneratedExtension<MessageT, List<T>> extension) {
return getExtensionCount((ExtensionLite<MessageT, List<T>>) extension);
}
/* Removed from GeneratedMessage.ExtendableMessage in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> T getExtension(final GeneratedExtension<MessageT, T> extension) {
return getExtension((ExtensionLite<MessageT, T>) extension);
}
/* Removed from GeneratedMessage.ExtendableMessage in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> T getExtension(
final GeneratedExtension<MessageT, List<T>> extension, final int index) {
return getExtension((ExtensionLite<MessageT, List<T>>) extension, index);
}
/* Overrides abstract GeneratedMessage.ExtendableMessage.internalGetFieldAccessorTable().
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableMessage.internalGetFieldAccessorTable() instead.
*/
@Deprecated
@Override
protected FieldAccessorTable internalGetFieldAccessorTable() {
throw new UnsupportedOperationException("Should be overridden in gencode.");
}
/**
* Stub for GeneratedMessageV3.ExtendableMessage.ExtensionWriter wrapping
* GeneratedMessage.ExtendableMessage.ExtensionWriter for compatibility with older gencode.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableMessage.ExtensionWriter instead.
*/
@Deprecated
protected class ExtensionWriter extends GeneratedMessage.ExtendableMessage.ExtensionWriter {
private ExtensionWriter(final boolean messageSetWireFormat) {
super(messageSetWireFormat);
}
}
/* Returns GeneratedMessageV3.ExtendableMessage.ExtensionWriter instead of
* GeneratedMessage.ExtendableMessage.ExtensionWriter.
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableMessage.newExtensionWriter() instead.
*/
@Deprecated
@Override
protected ExtensionWriter newExtensionWriter() {
return new ExtensionWriter(false);
}
/* Returns GeneratedMessageV3.ExtendableMessage.ExtensionWriter instead of
* GeneratedMessage.ExtendableMessage.ExtensionWriter.
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableMessage.newMessageSetExtensionWriter() instead.
*/
@Deprecated
@Override
protected ExtensionWriter newMessageSetExtensionWriter() {
return new ExtensionWriter(true);
}
}
/**
* Stub for GeneratedMessageV3.ExtendableBuilder wrapping GeneratedMessage.ExtendableBuilder for
* compatibility with older gencode.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x in 2025 Q1). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableBuilder instead of GeneratedMessageV3.ExtendableBuilder.
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableBuilder instead.
*/
@Deprecated
public abstract static class ExtendableBuilder<
MessageT extends ExtendableMessage<MessageT>,
BuilderT extends ExtendableBuilder<MessageT, BuilderT>>
extends GeneratedMessage.ExtendableBuilder<MessageT, BuilderT>
implements GeneratedMessage.ExtendableMessageOrBuilder<MessageT> {
extends Builder<BuilderT> // Extends GeneratedMessage.ExtendableBuilder via Builder
implements ExtendableMessageOrBuilder<MessageT> {
@Deprecated
protected ExtendableBuilder() {
super();
}
@Deprecated
protected ExtendableBuilder(BuilderParent parent) {
super(parent);
}
// Support old gencode override method removed in
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> boolean hasExtension(final GeneratedExtension<MessageT, T> extension) {
return hasExtension((ExtensionLite<MessageT, T>) extension);
}
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> int getExtensionCount(final GeneratedExtension<MessageT, List<T>> extension) {
return getExtensionCount((ExtensionLite<MessageT, List<T>>) extension);
}
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> T getExtension(final GeneratedExtension<MessageT, T> extension) {
return getExtension((ExtensionLite<MessageT, T>) extension);
}
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
@Override
public final <T> T getExtension(
final GeneratedExtension<MessageT, List<T>> extension, final int index) {
return getExtension((ExtensionLite<MessageT, List<T>>) extension, index);
}
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
public <T> BuilderT setExtension(
final GeneratedMessage.GeneratedExtension<MessageT, T> extension, final T value) {
return setExtension((ExtensionLite<MessageT, T>) extension, value);
}
// Support old gencode override method removed in
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
public <T> BuilderT setExtension(
final GeneratedMessage.GeneratedExtension<MessageT, List<T>> extension,
final int index,
@ -66,18 +546,141 @@ public abstract class GeneratedMessageV3 extends GeneratedMessage {
return setExtension((ExtensionLite<MessageT, List<T>>) extension, index, value);
}
// Support old gencode override method removed in
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
public <T> BuilderT addExtension(
final GeneratedMessage.GeneratedExtension<MessageT, List<T>> extension, final T value) {
return addExtension((ExtensionLite<MessageT, List<T>>) extension, value);
}
// Support old gencode override method removed in
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
/* Removed from GeneratedMessage.ExtendableBuilder in
* https://github.com/protocolbuffers/protobuf/commit/94a2a448518403341b8aa71335ab1123fbdcccd8
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which no longer overrides this method.
*/
@Deprecated
public <T> BuilderT clearExtension(
final GeneratedMessage.GeneratedExtension<MessageT, T> extension) {
return clearExtension((ExtensionLite<MessageT, T>) extension);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableBuilder.setField() instead. */
@Deprecated
@Override
public BuilderT setField(final FieldDescriptor field, final Object value) {
return super.setField(field, value);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableBuilder.clearField() instead. */
@Deprecated
@Override
public BuilderT clearField(final FieldDescriptor field) {
return super.clearField(field);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableBuilder.clearOneof() instead. */
@Deprecated
@Override
public BuilderT clearOneof(final OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableBuilder.setRepeatedField() instead. */
@Deprecated
@Override
public BuilderT setRepeatedField(
final FieldDescriptor field, final int index, final Object value) {
return super.setRepeatedField(field, index, value);
}
/* Stub for method overridden from old generated code removed in
* https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which overrides
* GeneratedMessage.ExtendableBuilder.addRepeatedField() instead. */
@Deprecated
@Override
public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) {
return super.addRepeatedField(field, value);
}
/* Stub for method called from old generated code.
* @Override not allowed despite inheriting from
* GeneratedMessage.ExtendableBuilder.mergeExtensionFields().
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ExtendableBuilder.mergeExtensionFields() instead. */
@Deprecated
protected final void mergeExtensionFields(final ExtendableMessage<?> other) {
super.mergeExtensionFields(other);
}
}
/**
* Stub for GeneratedMessageV3.FieldAccessorTable wrapping GeneratedMessage.FieldAccessorTable for
* compatibility with older gencode.
*
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.FieldAccessorTable instead.
*/
@Deprecated
public static final class FieldAccessorTable extends GeneratedMessage.FieldAccessorTable {
@Deprecated
public FieldAccessorTable(
final Descriptor descriptor,
final String[] camelCaseNames,
final Class<? extends GeneratedMessageV3> messageClass,
final Class<? extends Builder<?>> builderClass) {
super(descriptor, camelCaseNames, messageClass, builderClass);
}
@Deprecated
public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) {
super(descriptor, camelCaseNames);
}
/* Returns GeneratedMessageV3.FieldAccessorTable instead of GeneratedMessage.FieldAccessorTable.
*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking
* change (5.x). Users should update gencode to >= 4.26.x which uses
* GeneratedMessage.ensureFieldAccessorsInitialized() instead.
*/
@Deprecated
@Override
public FieldAccessorTable ensureFieldAccessorsInitialized(
Class<? extends GeneratedMessage> messageClass,
Class<? extends GeneratedMessage.Builder<?>> builderClass) {
return (FieldAccessorTable) super.ensureFieldAccessorsInitialized(messageClass, builderClass);
}
}
}

Просмотреть файл

@ -7,28 +7,579 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.RandomAccess;
/**
* Stub for RepeatedFieldBuilderV3 wrapping RepeatedFieldBuilder for compatibility with older
* gencode.
* Stub for RepeatedFieldBuilderV3 matching RepeatedFieldBuilder for compatibility with older
* gencode. This cannot wrap RepeatedFieldBuilder directly due to RepeatedFieldBuilder having more
* restrictive extends GeneratedMessage for MType and BType.
*
* @deprecated This class is deprecated, and slated for removal in the next breaking change. Users
* should update gencode to >= 4.26.x which replaces RepeatedFieldBuilderV3 with
* RepeatedFieldBuilder.
*/
@Deprecated
public class RepeatedFieldBuilderV3<
MType extends GeneratedMessage,
BType extends GeneratedMessage.Builder,
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends RepeatedFieldBuilder<MType, BType, IType> {
implements AbstractMessage.BuilderParent {
private AbstractMessage.BuilderParent parent;
private List<MType> messages;
private boolean isMessagesListMutable;
private List<SingleFieldBuilderV3<MType, BType, IType>> builders;
private boolean isClean;
private MessageExternalList<MType, BType, IType> externalMessageList;
private BuilderExternalList<MType, BType, IType> externalBuilderList;
private MessageOrBuilderExternalList<MType, BType, IType> externalMessageOrBuilderList;
@Deprecated
public RepeatedFieldBuilderV3(
List<MType> messages,
boolean isMessagesListMutable,
GeneratedMessage.BuilderParent parent,
AbstractMessage.BuilderParent parent,
boolean isClean) {
super(messages, isMessagesListMutable, parent, isClean);
this.messages = messages;
this.isMessagesListMutable = isMessagesListMutable;
this.parent = parent;
this.isClean = isClean;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.dispose() instead.
*/
@Deprecated
public void dispose() {
parent = null;
}
private void ensureMutableMessageList() {
if (!isMessagesListMutable) {
messages = new ArrayList<MType>(messages);
isMessagesListMutable = true;
}
}
private void ensureBuilders() {
if (this.builders == null) {
this.builders = new ArrayList<SingleFieldBuilderV3<MType, BType, IType>>(messages.size());
for (int i = 0; i < messages.size(); i++) {
builders.add(null);
}
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getCount() instead.
*/
@Deprecated
public int getCount() {
return messages.size();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.isEmpty() instead.
*/
@Deprecated
public boolean isEmpty() {
return messages.isEmpty();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getMessage() instead.
*/
@Deprecated
public MType getMessage(int index) {
return getMessage(index, false);
}
private MType getMessage(int index, boolean forBuild) {
if (this.builders == null) {
return messages.get(index);
}
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
return messages.get(index);
} else {
return forBuild ? builder.build() : builder.getMessage();
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getBuilder() instead.
*/
@Deprecated
public BType getBuilder(int index) {
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
MType message = messages.get(index);
builder = new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
builders.set(index, builder);
}
return builder.getBuilder();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getMessageOrBuilder() instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
public IType getMessageOrBuilder(int index) {
if (this.builders == null) {
return (IType) messages.get(index);
}
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
return (IType) messages.get(index);
} else {
return builder.getMessageOrBuilder();
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.setMessage() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.set(index, message);
if (builders != null) {
SingleFieldBuilderV3<MType, BType, IType> entry = builders.set(index, null);
if (entry != null) {
entry.dispose();
}
}
onChanged();
incrementModCounts();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.addMessage() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.add(message);
if (builders != null) {
builders.add(null);
}
onChanged();
incrementModCounts();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.addMessage() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.add(index, message);
if (builders != null) {
builders.add(index, null);
}
onChanged();
incrementModCounts();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.addAllMessages() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(
Iterable<? extends MType> values) {
for (final MType value : values) {
checkNotNull(value);
}
int size = -1;
if (values instanceof Collection) {
final Collection<?> collection = (Collection<?>) values;
if (collection.isEmpty()) {
return this;
}
size = collection.size();
}
ensureMutableMessageList();
if (size >= 0 && messages instanceof ArrayList) {
((ArrayList<MType>) messages).ensureCapacity(messages.size() + size);
}
for (MType value : values) {
addMessage(value);
}
onChanged();
incrementModCounts();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.addBuilder() instead.
*/
@Deprecated
public BType addBuilder(MType message) {
ensureMutableMessageList();
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder =
new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
messages.add(null);
builders.add(builder);
onChanged();
incrementModCounts();
return builder.getBuilder();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.addBuilder() instead.
*/
@Deprecated
public BType addBuilder(int index, MType message) {
ensureMutableMessageList();
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder =
new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
messages.add(index, null);
builders.add(index, builder);
onChanged();
incrementModCounts();
return builder.getBuilder();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.remove() instead.
*/
@Deprecated
public void remove(int index) {
ensureMutableMessageList();
messages.remove(index);
if (builders != null) {
SingleFieldBuilderV3<MType, BType, IType> entry = builders.remove(index);
if (entry != null) {
entry.dispose();
}
}
onChanged();
incrementModCounts();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.clear() instead.
*/
@Deprecated
public void clear() {
messages = Collections.emptyList();
isMessagesListMutable = false;
if (builders != null) {
for (SingleFieldBuilderV3<MType, BType, IType> entry : builders) {
if (entry != null) {
entry.dispose();
}
}
builders = null;
}
onChanged();
incrementModCounts();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.build() instead.
*/
@Deprecated
public List<MType> build() {
isClean = true;
if (!isMessagesListMutable && builders == null) {
return messages;
}
boolean allMessagesInSync = true;
if (!isMessagesListMutable) {
for (int i = 0; i < messages.size(); i++) {
Message message = messages.get(i);
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(i);
if (builder != null) {
if (builder.build() != message) {
allMessagesInSync = false;
break;
}
}
}
if (allMessagesInSync) {
return messages;
}
}
ensureMutableMessageList();
for (int i = 0; i < messages.size(); i++) {
messages.set(i, getMessage(i, true));
}
messages = Collections.unmodifiableList(messages);
isMessagesListMutable = false;
return messages;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getMessageList() instead.
*/
@Deprecated
public List<MType> getMessageList() {
if (externalMessageList == null) {
externalMessageList = new MessageExternalList<MType, BType, IType>(this);
}
return externalMessageList;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getBuilderList() instead.
*/
@Deprecated
public List<BType> getBuilderList() {
if (externalBuilderList == null) {
externalBuilderList = new BuilderExternalList<MType, BType, IType>(this);
}
return externalBuilderList;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.getMessageOrBuilderList() instead.
*/
@Deprecated
public List<IType> getMessageOrBuilderList() {
if (externalMessageOrBuilderList == null) {
externalMessageOrBuilderList = new MessageOrBuilderExternalList<MType, BType, IType>(this);
}
return externalMessageOrBuilderList;
}
private void onChanged() {
if (isClean && parent != null) {
parent.markDirty();
isClean = false;
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.markDirty() instead.
*/
@Deprecated
@Override
public void markDirty() {
onChanged();
}
private void incrementModCounts() {
if (externalMessageList != null) {
externalMessageList.incrementModCount();
}
if (externalBuilderList != null) {
externalBuilderList.incrementModCount();
}
if (externalMessageOrBuilderList != null) {
externalMessageOrBuilderList.incrementModCount();
}
}
private static class MessageExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<MType> implements List<MType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
@Deprecated
MessageExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageExternalList.size() instead.
*/
@Deprecated
@Override
public int size() {
return this.builder.getCount();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageExternalList.get() instead.
*/
@Deprecated
@Override
public MType get(int index) {
return builder.getMessage(index);
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageExternalList.incrementModCount() instead.
*/
@Deprecated
void incrementModCount() {
modCount++;
}
}
private static class BuilderExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<BType> implements List<BType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
@Deprecated
BuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.BuilderExternalList.size() instead.
*/
@Deprecated
@Override
public int size() {
return this.builder.getCount();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.BuilderExternalList.get() instead.
*/
@Deprecated
@Override
public BType get(int index) {
return builder.getBuilder(index);
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.BuilderExternalList.incrementModCount() instead.
*/
@Deprecated
void incrementModCount() {
modCount++;
}
}
private static class MessageOrBuilderExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<IType> implements List<IType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
MessageOrBuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageOrBuilderExternalList.size() instead.
*/
@Deprecated
@Override
public int size() {
return this.builder.getCount();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageOrBuilderExternalList.get() instead.
*/
@Deprecated
@Override
public IType get(int index) {
return builder.getMessageOrBuilder(index);
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* RepeatedFieldBuilder.MessageOrBuilderExternalList.incrementModCount() instead.
*/
@Deprecated
void incrementModCount() {
modCount++;
}
}
}

Просмотреть файл

@ -7,8 +7,12 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
/**
* Stub for SingleFieldBuilderV3 wrapping SingleFieldBuilder for compatibility with older gencode.
* Stub for SingleFieldBuilderV3 matching SingleFieldBuilder for compatibility with older gencode.
* This cannot wrap SingleFieldBuilder directly due to SingleFieldBuilder having more restrictive
* extends GeneratedMessage for MType and BType.
*
* @deprecated This class is deprecated, and slated for removal in the next breaking change. Users
* should update gencode to >= 4.26.x which replaces SingleFieldBuilderV3 with
@ -16,13 +20,175 @@ package com.google.protobuf;
*/
@Deprecated
public class SingleFieldBuilderV3<
MType extends GeneratedMessage,
BType extends GeneratedMessage.Builder,
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends SingleFieldBuilder<MType, BType, IType> {
implements AbstractMessage.BuilderParent {
private AbstractMessage.BuilderParent parent;
private BType builder;
private MType message;
private boolean isClean;
@Deprecated
public SingleFieldBuilderV3(
MType message, GeneratedMessage.BuilderParent parent, boolean isClean) {
super(message, parent, isClean);
MType message, AbstractMessage.BuilderParent parent, boolean isClean) {
this.message = checkNotNull(message);
this.parent = parent;
this.isClean = isClean;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.dispose() instead.
*/
@Deprecated
public void dispose() {
parent = null;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.getMessage() instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
public MType getMessage() {
if (message == null) {
message = (MType) builder.buildPartial();
}
return message;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.build() instead.
*/
@Deprecated
public MType build() {
isClean = true;
return getMessage();
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.getbuilder() instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
public BType getBuilder() {
if (builder == null) {
builder = (BType) message.newBuilderForType(this);
builder.mergeFrom(message);
builder.markClean();
}
return builder;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.getMessageOrBuilder() instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
public IType getMessageOrBuilder() {
if (builder != null) {
return (IType) builder;
} else {
return (IType) message;
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.setMessage() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> setMessage(MType message) {
this.message = checkNotNull(message);
if (builder != null) {
builder.dispose();
builder = null;
}
onChanged();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.mergeFrom() instead.
*/
@Deprecated
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> mergeFrom(MType value) {
if (builder == null && message == message.getDefaultInstanceForType()) {
message = value;
} else {
getBuilder().mergeFrom(value);
}
onChanged();
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.clear() instead.
*/
@Deprecated
@SuppressWarnings("unchecked")
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> clear() {
message =
(MType)
(message != null
? message.getDefaultInstanceForType()
: builder.getDefaultInstanceForType());
if (builder != null) {
builder.dispose();
builder = null;
}
onChanged();
isClean = true;
return this;
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.onChanged() instead.
*/
@Deprecated
private void onChanged() {
if (builder != null) {
message = null;
}
if (isClean && parent != null) {
parent.markDirty();
isClean = false;
}
}
/*
* @deprecated This method is deprecated, and slated for removal in the next Java breaking change
* (5.x). Users should update gencode to >= 4.26.x which uses
* SingleFieldBuilder.markDirty() instead.
*/
@Deprecated
@Override
public void markDirty() {
onChanged();
}
}

Просмотреть файл

@ -45,6 +45,7 @@ def junit_tests(name, srcs, data = [], deps = [], package_name = "com.google.pro
deps = deps,
resources = data,
data = data,
testonly = True,
)
test_names = []
prefix = name.replace("-", "_") + "TestSuite"