Skip to content

Commit

Permalink
Merge pull request #3988 from acozzette/down-integrate
Browse files Browse the repository at this point in the history
Integrated internal changes from Google
  • Loading branch information
Adam Cozzette committed Dec 5, 2017
2 parents 173f304 + e372df5 commit 9021f62
Show file tree
Hide file tree
Showing 142 changed files with 4,456 additions and 3,270 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -204,6 +204,7 @@ java_EXTRA_DIST=
java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java \ java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java \
java/core/src/main/java/com/google/protobuf/AbstractParser.java \ java/core/src/main/java/com/google/protobuf/AbstractParser.java \
java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java \ java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java \
java/core/src/main/java/com/google/protobuf/Android.java \
java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java \ java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java \
java/core/src/main/java/com/google/protobuf/BlockingService.java \ java/core/src/main/java/com/google/protobuf/BlockingService.java \
java/core/src/main/java/com/google/protobuf/BooleanArrayList.java \ java/core/src/main/java/com/google/protobuf/BooleanArrayList.java \
Expand Down
2 changes: 2 additions & 0 deletions cmake/libprotobuf-lite.cmake
Expand Up @@ -4,6 +4,7 @@ set(libprotobuf_lite_files
${protobuf_source_dir}/src/google/protobuf/extension_set.cc ${protobuf_source_dir}/src/google/protobuf/extension_set.cc
${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven_lite.cc ${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven_lite.cc
${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc ${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc
${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc
${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
Expand Down Expand Up @@ -31,6 +32,7 @@ set(libprotobuf_lite_includes
${protobuf_source_dir}/src/google/protobuf/arenastring.h ${protobuf_source_dir}/src/google/protobuf/arenastring.h
${protobuf_source_dir}/src/google/protobuf/extension_set.h ${protobuf_source_dir}/src/google/protobuf/extension_set.h
${protobuf_source_dir}/src/google/protobuf/generated_message_util.h ${protobuf_source_dir}/src/google/protobuf/generated_message_util.h
${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.h
${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
Expand Down
1 change: 0 additions & 1 deletion conformance/failure_list_cpp.txt
Expand Up @@ -54,4 +54,3 @@ Required.Proto2.ProtobufInput.PrematureEofInPackedField.SINT32
Required.Proto2.ProtobufInput.PrematureEofInPackedField.SINT64 Required.Proto2.ProtobufInput.PrematureEofInPackedField.SINT64
Required.Proto2.ProtobufInput.PrematureEofInPackedField.UINT32 Required.Proto2.ProtobufInput.PrematureEofInPackedField.UINT32
Required.Proto2.ProtobufInput.PrematureEofInPackedField.UINT64 Required.Proto2.ProtobufInput.PrematureEofInPackedField.UINT64

2 changes: 1 addition & 1 deletion conformance/failure_list_java.txt
Expand Up @@ -44,4 +44,4 @@ Required.Proto3.JsonInput.StringFieldNotAString
Required.Proto3.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE Required.Proto3.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE
Required.Proto3.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE Required.Proto3.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE
Required.Proto2.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE Required.Proto2.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE
Required.Proto2.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE Required.Proto2.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE
21 changes: 13 additions & 8 deletions csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
Expand Up @@ -154,17 +154,18 @@ public sealed partial class Any : pb::IMessage<Any> {
public const int TypeUrlFieldNumber = 1; public const int TypeUrlFieldNumber = 1;
private string typeUrl_ = ""; private string typeUrl_ = "";
/// <summary> /// <summary>
/// A URL/resource name whose content describes the type of the /// A URL/resource name that uniquely identifies the type of the serialized
/// serialized protocol buffer message. /// protocol buffer message. The last segment of the URL's path must represent
/// the fully qualified name of the type (as in
/// `path/google.protobuf.Duration`). The name should be in a canonical form
/// (e.g., leading "." is not accepted).
/// ///
/// For URLs which use the scheme `http`, `https`, or no scheme, the /// In practice, teams usually precompile into the binary all types that they
/// following restrictions and interpretations apply: /// expect it to use in the context of Any. However, for URLs which use the
/// scheme `http`, `https`, or no scheme, one can optionally set up a type
/// server that maps type URLs to message definitions as follows:
/// ///
/// * If no scheme is provided, `https` is assumed. /// * If no scheme is provided, `https` is assumed.
/// * The last segment of the URL's path must represent the fully
/// qualified name of the type (as in `path/google.protobuf.Duration`).
/// The name should be in a canonical form (e.g., leading "." is
/// not accepted).
/// * An HTTP GET on the URL must yield a [google.protobuf.Type][] /// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
/// value in binary format, or produce an error. /// value in binary format, or produce an error.
/// * Applications are allowed to cache lookup results based on the /// * Applications are allowed to cache lookup results based on the
Expand All @@ -173,6 +174,10 @@ public sealed partial class Any : pb::IMessage<Any> {
/// on changes to types. (Use versioned type names to manage /// on changes to types. (Use versioned type names to manage
/// breaking changes.) /// breaking changes.)
/// ///
/// Note: this functionality is not currently available in the official
/// protobuf release, and it is not used for type URLs beginning with
/// type.googleapis.com.
///
/// Schemes other than `http`, `https` (or the empty scheme) might be /// Schemes other than `http`, `https` (or the empty scheme) might be
/// used with implementation specific semantics. /// used with implementation specific semantics.
/// </summary> /// </summary>
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
Expand Up @@ -112,8 +112,8 @@ public static partial class TimestampReflection {
/// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) /// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
/// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one /// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
/// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( /// can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
/// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--) /// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
/// to obtain a formatter capable of generating timestamps in this format. /// ) to obtain a formatter capable of generating timestamps in this format.
/// </summary> /// </summary>
public sealed partial class Timestamp : pb::IMessage<Timestamp> { public sealed partial class Timestamp : pb::IMessage<Timestamp> {
private static readonly pb::MessageParser<Timestamp> _parser = new pb::MessageParser<Timestamp>(() => new Timestamp()); private static readonly pb::MessageParser<Timestamp> _parser = new pb::MessageParser<Timestamp>(() => new Timestamp());
Expand Down
57 changes: 57 additions & 0 deletions java/core/src/main/java/com/google/protobuf/Android.java
@@ -0,0 +1,57 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package com.google.protobuf;

final class Android {

private static final Class<?> MEMORY_CLASS = getClassForName("libcore.io.Memory");
private static final boolean IS_ROBOLECTRIC =
getClassForName("org.robolectric.Robolectric") != null;

/** Returns {@code true} if running on an Android device. */
static boolean isOnAndroidDevice() {
return MEMORY_CLASS != null && !IS_ROBOLECTRIC;
}

/** Returns the memory class or {@code null} if not on Android device. */
static Class<?> getMemoryClass() {
return MEMORY_CLASS;
}

@SuppressWarnings("unchecked")
private static <T> Class<T> getClassForName(String name) {
try {
return (Class<T>) Class.forName(name);
} catch (Throwable e) {
return null;
}
}
}
10 changes: 2 additions & 8 deletions java/core/src/main/java/com/google/protobuf/ByteString.java
Expand Up @@ -124,14 +124,8 @@ public byte[] copyFrom(byte[] bytes, int offset, int size) {


private static final ByteArrayCopier byteArrayCopier; private static final ByteArrayCopier byteArrayCopier;
static { static {
boolean isAndroid = true; byteArrayCopier =
try { Android.isOnAndroidDevice() ? new SystemByteArrayCopier() : new ArraysByteArrayCopier();
Class.forName("android.content.Context");
} catch (ClassNotFoundException e) {
isAndroid = false;
}

byteArrayCopier = isAndroid ? new SystemByteArrayCopier() : new ArraysByteArrayCopier();
} }


/** /**
Expand Down
5 changes: 5 additions & 0 deletions java/core/src/main/java/com/google/protobuf/FieldSet.java
Expand Up @@ -102,6 +102,11 @@ FieldSet<T> emptySet() {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final FieldSet DEFAULT_INSTANCE = new FieldSet(true); private static final FieldSet DEFAULT_INSTANCE = new FieldSet(true);


/** Returns {@code true} if empty, {@code false} otherwise. */
boolean isEmpty() {
return fields.isEmpty();
}

/** Make this FieldSet immutable from this point forward. */ /** Make this FieldSet immutable from this point forward. */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void makeImmutable() { public void makeImmutable() {
Expand Down
Expand Up @@ -504,11 +504,8 @@ public abstract static class ExtendableMessage<
extends GeneratedMessageLite<MessageType, BuilderType> extends GeneratedMessageLite<MessageType, BuilderType>
implements ExtendableMessageOrBuilder<MessageType, BuilderType> { implements ExtendableMessageOrBuilder<MessageType, BuilderType> {


/** /** Represents the set of extensions on this message. For use by generated code only. */
* Represents the set of extensions on this message. For use by generated protected FieldSet<ExtensionDescriptor> extensions = FieldSet.emptySet();
* code only.
*/
protected FieldSet<ExtensionDescriptor> extensions = FieldSet.newFieldSet();


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected final void mergeExtensionFields(final MessageType other) { protected final void mergeExtensionFields(final MessageType other) {
Expand Down Expand Up @@ -578,7 +575,11 @@ private boolean parseExtension(
if (unknown) { // Unknown field or wrong wire type. Skip. if (unknown) { // Unknown field or wrong wire type. Skip.
return parseUnknownField(tag, input); return parseUnknownField(tag, input);
} }


if (extensions.isImmutable()) {
extensions = extensions.clone();
}

if (packed) { if (packed) {
int length = input.readRawVarint32(); int length = input.readRawVarint32();
int limit = input.pushLimit(length); int limit = input.pushLimit(length);
Expand Down Expand Up @@ -942,12 +943,6 @@ public abstract static class ExtendableBuilder<
implements ExtendableMessageOrBuilder<MessageType, BuilderType> { implements ExtendableMessageOrBuilder<MessageType, BuilderType> {
protected ExtendableBuilder(MessageType defaultInstance) { protected ExtendableBuilder(MessageType defaultInstance) {
super(defaultInstance); super(defaultInstance);

// TODO(dweis): This is kind of an unnecessary clone since we construct a
// new instance in the parent constructor which makes the extensions
// immutable. This extra allocation shouldn't matter in practice
// though.
instance.extensions = instance.extensions.clone();
} }


// For immutable message conversion. // For immutable message conversion.
Expand All @@ -966,6 +961,15 @@ protected void copyOnWrite() {
instance.extensions = instance.extensions.clone(); instance.extensions = instance.extensions.clone();
} }


private FieldSet<ExtensionDescriptor> ensureExtensionsAreMutable() {
FieldSet<ExtensionDescriptor> extensions = instance.extensions;
if (extensions.isImmutable()) {
extensions = extensions.clone();
instance.extensions = extensions;
}
return extensions;
}

@Override @Override
public final MessageType buildPartial() { public final MessageType buildPartial() {
if (isBuilt) { if (isBuilt) {
Expand Down Expand Up @@ -1024,7 +1028,8 @@ public final <Type> BuilderType setExtension(


verifyExtensionContainingType(extensionLite); verifyExtensionContainingType(extensionLite);
copyOnWrite(); copyOnWrite();
instance.extensions.setField(extensionLite.descriptor, extensionLite.toFieldSetType(value)); ensureExtensionsAreMutable()
.setField(extensionLite.descriptor, extensionLite.toFieldSetType(value));
return (BuilderType) this; return (BuilderType) this;
} }


Expand All @@ -1037,8 +1042,9 @@ public final <Type> BuilderType setExtension(


verifyExtensionContainingType(extensionLite); verifyExtensionContainingType(extensionLite);
copyOnWrite(); copyOnWrite();
instance.extensions.setRepeatedField( ensureExtensionsAreMutable()
extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value)); .setRepeatedField(
extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value));
return (BuilderType) this; return (BuilderType) this;
} }


Expand All @@ -1051,8 +1057,8 @@ public final <Type> BuilderType addExtension(


verifyExtensionContainingType(extensionLite); verifyExtensionContainingType(extensionLite);
copyOnWrite(); copyOnWrite();
instance.extensions.addRepeatedField( ensureExtensionsAreMutable()
extensionLite.descriptor, extensionLite.singularToFieldSetType(value)); .addRepeatedField(extensionLite.descriptor, extensionLite.singularToFieldSetType(value));
return (BuilderType) this; return (BuilderType) this;
} }


Expand All @@ -1063,7 +1069,7 @@ public final <Type> BuilderType clearExtension(


verifyExtensionContainingType(extensionLite); verifyExtensionContainingType(extensionLite);
copyOnWrite(); copyOnWrite();
instance.extensions.clearField(extensionLite.descriptor); ensureExtensionsAreMutable().clearField(extensionLite.descriptor);
return (BuilderType) this; return (BuilderType) this;
} }
} }
Expand Down
35 changes: 35 additions & 0 deletions java/core/src/main/java/com/google/protobuf/TextFormat.java
Expand Up @@ -1223,6 +1223,22 @@ public static void merge(final CharSequence input,
PARSER.merge(input, builder); PARSER.merge(input, builder);
} }


/**
* Parse a text-format message from {@code input}.
*
* @return the parsed message, guaranteed initialized
*/
public static <T extends Message> T parse(final CharSequence input,
final Class<T> protoClass)
throws ParseException {
Message.Builder builder =
Internal.getDefaultInstance(protoClass).newBuilderForType();
merge(input, builder);
@SuppressWarnings("unchecked")
T output = (T) builder.build();
return output;
}

/** /**
* Parse a text-format message from {@code input} and merge the contents * Parse a text-format message from {@code input} and merge the contents
* into {@code builder}. Extensions will be recognized if they are * into {@code builder}. Extensions will be recognized if they are
Expand All @@ -1248,6 +1264,25 @@ public static void merge(final CharSequence input,
PARSER.merge(input, extensionRegistry, builder); PARSER.merge(input, extensionRegistry, builder);
} }


/**
* Parse a text-format message from {@code input}. Extensions will be
* recognized if they are registered in {@code extensionRegistry}.
*
* @return the parsed message, guaranteed initialized
*/
public static <T extends Message> T parse(
final CharSequence input,
final ExtensionRegistry extensionRegistry,
final Class<T> protoClass)
throws ParseException {
Message.Builder builder =
Internal.getDefaultInstance(protoClass).newBuilderForType();
merge(input, extensionRegistry, builder);
@SuppressWarnings("unchecked")
T output = (T) builder.build();
return output;
}



/** /**
* Parser for text-format proto2 instances. This class is thread-safe. * Parser for text-format proto2 instances. This class is thread-safe.
Expand Down
9 changes: 0 additions & 9 deletions java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
Expand Up @@ -385,15 +385,6 @@ private static boolean supportsUnsafeByteBufferOperations() {
} }




@SuppressWarnings("unchecked")
private static <T> Class<T> getClassForName(String name) {
try {
return (Class<T>) Class.forName(name);
} catch (Throwable e) {
return null;
}
}

/** Finds the address field within a direct {@link Buffer}. */ /** Finds the address field within a direct {@link Buffer}. */
private static Field bufferAddressField() { private static Field bufferAddressField() {
return field(Buffer.class, "address", long.class); return field(Buffer.class, "address", long.class);
Expand Down
Expand Up @@ -30,6 +30,9 @@


package com.google.protobuf; package com.google.protobuf;


import static com.google.protobuf.TestUtil.TEST_REQUIRED_INITIALIZED;
import static com.google.protobuf.TestUtil.TEST_REQUIRED_UNINITIALIZED;

import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor;
import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize; import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
import protobuf_unittest.UnittestProto; import protobuf_unittest.UnittestProto;
Expand Down Expand Up @@ -346,11 +349,6 @@ public void testOptimizedForSize() throws Exception {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Tests for isInitialized(). // Tests for isInitialized().


private static final TestRequired TEST_REQUIRED_UNINITIALIZED =
TestRequired.getDefaultInstance();
private static final TestRequired TEST_REQUIRED_INITIALIZED =
TestRequired.newBuilder().setA(1).setB(2).setC(3).build();

public void testIsInitialized() throws Exception { public void testIsInitialized() throws Exception {
TestRequired.Builder builder = TestRequired.newBuilder(); TestRequired.Builder builder = TestRequired.newBuilder();
AbstractMessageWrapper.Builder abstractBuilder = AbstractMessageWrapper.Builder abstractBuilder =
Expand Down Expand Up @@ -380,7 +378,7 @@ public void testForeignIsInitialized() throws Exception {
builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED); builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED);
assertFalse(abstractBuilder.isInitialized()); assertFalse(abstractBuilder.isInitialized());
assertEquals( assertEquals(
"optional_message.a, optional_message.b, optional_message.c", "optional_message.b, optional_message.c",
abstractBuilder.getInitializationErrorString()); abstractBuilder.getInitializationErrorString());


builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED); builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED);
Expand All @@ -390,7 +388,7 @@ public void testForeignIsInitialized() throws Exception {
builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED); builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED);
assertFalse(abstractBuilder.isInitialized()); assertFalse(abstractBuilder.isInitialized());
assertEquals( assertEquals(
"repeated_message[0].a, repeated_message[0].b, repeated_message[0].c", "repeated_message[0].b, repeated_message[0].c",
abstractBuilder.getInitializationErrorString()); abstractBuilder.getInitializationErrorString());


builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED); builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED);
Expand Down
6 changes: 6 additions & 0 deletions java/core/src/test/java/com/google/protobuf/TestUtil.java
Expand Up @@ -231,6 +231,7 @@
import protobuf_unittest.UnittestProto.TestOneof2; import protobuf_unittest.UnittestProto.TestOneof2;
import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions;
import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestPackedTypes;
import protobuf_unittest.UnittestProto.TestRequired;
import protobuf_unittest.UnittestProto.TestUnpackedTypes; import protobuf_unittest.UnittestProto.TestUnpackedTypes;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
Expand All @@ -252,6 +253,11 @@
public final class TestUtil { public final class TestUtil {
private TestUtil() {} private TestUtil() {}


public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
TestRequired.newBuilder().setA(1).buildPartial();
public static final TestRequired TEST_REQUIRED_INITIALIZED =
TestRequired.newBuilder().setA(1).setB(2).setC(3).build();

/** Helper to convert a String to ByteString. */ /** Helper to convert a String to ByteString. */
static ByteString toBytes(String str) { static ByteString toBytes(String str) {
return ByteString.copyFrom(str.getBytes(Internal.UTF_8)); return ByteString.copyFrom(str.getBytes(Internal.UTF_8));
Expand Down

3 comments on commit 9021f62

@nlopezgi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My protobuf bazel builds started failing with this CL. I run tests on both a debian8-clang and an ubuntu-gcc environments. Tests fail on both environments with a similar error message:

Message on debian8-clang (gcr.io/cloud-marketplace/google/clang-debian8)
ERROR: /protobuf/BUILD:473:1: Linking of rule '//:test_plugin' failed (Exit 1): clang failed: error executing command
(cd /root/.cache/bazel/_bazel_root/c10d995b71ee2cb34bd3247d67c66df9/execroot/com_google_protobuf &&
exec env -
PWD=/proc/self/cwd
/usr/local/bin/clang -o bazel-out/k8-fastbuild/bin/test_plugin -pthread '-fuse-ld=gold' -B/usr/local/bin -B/usr/bin -Wl,-S -Wl,@bazel-out/k8-fastbuild/bin/test_plugin-2.params)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::RepeatedPtrFieldBase::AddWeak(google::protobuf::MessageLite const*): error: undefined reference to 'typeinfo for google::protobuf::internal::ImplicitWeakMessage'
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::ImplicitWeakMessage::ImplicitWeakMessage(): error: undefined reference to 'vtable for google::protobuf::internal::ImplicitWeakMessage'
/usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::ImplicitWeakMessage::ImplicitWeakMessage(google::protobuf::Arena*): error: undefined reference to 'vtable for google::protobuf::internal::ImplicitWeakMessage'
/usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
Target //:protobuf_test failed to build

Message on ubuntu-trusty-gcc (stock ubuntu:trusty with gcc + bazel installed):
ERROR: /project_src/BUILD:473:1: Linking of rule '//:test_plugin' failed (Exit 1): gcc failed: error executing command
(cd /root/.cache/bazel/_bazel_root/7e958634aed2e0b9513fa7cce861a282/execroot/com_google_protobuf &&
exec env -
PWD=/proc/self/cwd
/usr/bin/gcc -o bazel-out/k8-fastbuild/bin/test_plugin -pthread '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,-S -Wl,@bazel-out/k8-fastbuild/bin/test_plugin-2.params)
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::RepeatedPtrFieldBase::AddWeak(google::protobuf::MessageLite const*): error: undefined reference to 'typeinfo for google::protobuf::internal::ImplicitWeakMessage'
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::ImplicitWeakMessage::ImplicitWeakMessage(): error: undefined reference to 'vtable for google::protobuf::internal::ImplicitWeakMessage'
/usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function
bazel-out/k8-fastbuild/bin/_objs/protobuf_lite/src/google/protobuf/repeated_field.pic.o:repeated_field.cc:function google::protobuf::internal::ImplicitWeakMessage::ImplicitWeakMessage(google::protobuf::Arena*): error: undefined reference to 'vtable for google::protobuf::internal::ImplicitWeakMessage'
/usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function
collect2: error: ld returned 1 exit status
Target //:protobuf_test failed to build

@acozzette
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nlopezgi Sorry about that, I've just sent out pull request #4017 which should fix this.

@nlopezgi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the quick response, our builds are now green

Please sign in to comment.