Skip to content

Commit 6dd2176

Browse files
committed
Sync from Piper @396393195
PROTOBUF_SYNC_PIPER
1 parent 215dd13 commit 6dd2176

File tree

7 files changed

+125
-54
lines changed

7 files changed

+125
-54
lines changed

BUILD

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ cc_library(
133133
"src/google/protobuf/extension_set.cc",
134134
"src/google/protobuf/generated_enum_util.cc",
135135
"src/google/protobuf/generated_message_table_driven_lite.cc",
136+
"src/google/protobuf/generated_message_tctable_lite.cc",
136137
"src/google/protobuf/generated_message_util.cc",
137138
"src/google/protobuf/implicit_weak_message.cc",
138139
"src/google/protobuf/inlined_string_field.cc",
@@ -193,6 +194,7 @@ cc_library(
193194
"src/google/protobuf/generated_message_bases.cc",
194195
"src/google/protobuf/generated_message_reflection.cc",
195196
"src/google/protobuf/generated_message_table_driven.cc",
197+
"src/google/protobuf/generated_message_tctable_full.cc",
196198
"src/google/protobuf/io/gzip_stream.cc",
197199
"src/google/protobuf/io/printer.cc",
198200
"src/google/protobuf/io/tokenizer.cc",
@@ -222,7 +224,6 @@ cc_library(
222224
"src/google/protobuf/util/internal/protostream_objectsource.cc",
223225
"src/google/protobuf/util/internal/protostream_objectwriter.cc",
224226
"src/google/protobuf/util/internal/type_info.cc",
225-
"src/google/protobuf/util/internal/type_info_test_helper.cc",
226227
"src/google/protobuf/util/internal/utility.cc",
227228
"src/google/protobuf/util/json_util.cc",
228229
"src/google/protobuf/util/message_differencer.cc",
@@ -621,6 +622,8 @@ cc_proto_library(
621622
COMMON_TEST_SRCS = [
622623
# AUTOGEN(common_test_srcs)
623624
"src/google/protobuf/arena_test_util.cc",
625+
"src/google/protobuf/map_lite_test_util.cc",
626+
"src/google/protobuf/test_util_lite.cc",
624627
"src/google/protobuf/map_test_util.inc",
625628
"src/google/protobuf/reflection_tester.cc",
626629
"src/google/protobuf/test_util.cc",

conformance/conformance_nodejs.js

100644100755
+1-34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env node
12
// Protocol Buffers - Google's data interchange format
23
// Copyright 2008 Google Inc. All rights reserved.
34
// https://developers.google.com/protocol-buffers/
@@ -28,40 +29,6 @@
2829
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2930
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3031

31-
#!/usr/bin/env node
32-
33-
/*
34-
* Protocol Buffers - Google's data interchange format
35-
* Copyright 2008 Google Inc. All rights reserved.
36-
* https://developers.google.com/protocol-buffers/
37-
*
38-
* Redistribution and use in source and binary forms, with or without
39-
* modification, are permitted provided that the following conditions are
40-
* met:
41-
*
42-
* * Redistributions of source code must retain the above copyright
43-
* notice, this list of conditions and the following disclaimer.
44-
* * Redistributions in binary form must reproduce the above
45-
* copyright notice, this list of conditions and the following disclaimer
46-
* in the documentation and/or other materials provided with the
47-
* distribution.
48-
* * Neither the name of Google Inc. nor the names of its
49-
* contributors may be used to endorse or promote products derived from
50-
* this software without specific prior written permission.
51-
*
52-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55-
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56-
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58-
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59-
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60-
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63-
*/
64-
6532
var conformance = require('conformance_pb');
6633
var test_messages_proto3 = require('google/protobuf/test_messages_proto3_pb');
6734
var test_messages_proto2 = require('google/protobuf/test_messages_proto2_pb');

java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java

+33
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static com.google.common.truth.Truth.assertThat;
3434
import static com.google.common.truth.Truth.assertWithMessage;
35+
import static org.junit.Assert.fail;
3536

3637
import map_lite_test.MapForProto2TestProto.BizarroTestMap;
3738
import map_lite_test.MapForProto2TestProto.TestMap;
@@ -43,6 +44,7 @@
4344
import java.util.ArrayList;
4445
import java.util.HashMap;
4546
import java.util.Map;
47+
import java.util.TreeMap;
4648
import org.junit.Test;
4749
import org.junit.runner.RunWith;
4850
import org.junit.runners.JUnit4;
@@ -803,4 +805,35 @@ public void testRemove() {
803805
// expected
804806
}
805807
}
808+
809+
@Test
810+
public void testPutAllWithNullStringValue() throws Exception {
811+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
812+
813+
// order preserving map used here to help test rollback
814+
Map<Integer, String> data = new TreeMap<>();
815+
data.put(7, "foo");
816+
data.put(8, "bar");
817+
data.put(9, null);
818+
try {
819+
sourceBuilder.putAllInt32ToStringField(data);
820+
fail("allowed null string value");
821+
} catch (NullPointerException expected) {
822+
// Verify rollback of previously added values.
823+
// They all go in or none do.
824+
assertThat(sourceBuilder.getInt32ToStringFieldMap()).isEmpty();
825+
}
826+
}
827+
828+
@Test
829+
public void testPutNullStringValue() throws Exception {
830+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
831+
832+
try {
833+
sourceBuilder.putInt32ToStringField(8, null);
834+
fail("allowed null string value");
835+
} catch (NullPointerException expected) {
836+
}
837+
}
838+
806839
}

java/core/src/test/java/com/google/protobuf/MapForProto2Test.java

+34-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
import static com.google.common.truth.Truth.assertThat;
3434
import static com.google.common.truth.Truth.assertWithMessage;
35+
import static org.junit.Assert.assertNotNull;
36+
import static org.junit.Assert.fail;
3537

3638
import com.google.protobuf.Descriptors.FieldDescriptor;
3739
import map_test.MapForProto2TestProto.BizarroTestMap;
@@ -51,6 +53,7 @@
5153
import java.util.HashMap;
5254
import java.util.List;
5355
import java.util.Map;
56+
import java.util.TreeMap;
5457
import org.junit.Test;
5558
import org.junit.runner.RunWith;
5659
import org.junit.runners.JUnit4;
@@ -484,13 +487,6 @@ public void testPutAll() throws Exception {
484487
public void testPutChecksNullKeysAndValues() throws Exception {
485488
TestMap.Builder builder = TestMap.newBuilder();
486489

487-
try {
488-
builder.putInt32ToStringField(1, null);
489-
assertWithMessage("expected exception").fail();
490-
} catch (NullPointerException e) {
491-
// expected.
492-
}
493-
494490
try {
495491
builder.putInt32ToBytesField(1, null);
496492
assertWithMessage("expected exception").fail();
@@ -1218,4 +1214,35 @@ public void testGetMap() {
12181214
assertThat(message.getInt32ToEnumFieldMap()).isEqualTo(message.getInt32ToEnumFieldMap());
12191215
assertThat(message.getInt32ToMessageFieldMap()).isEqualTo(message.getInt32ToMessageFieldMap());
12201216
}
1217+
1218+
@Test
1219+
public void testPutAllWithNullStringValue() throws Exception {
1220+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
1221+
1222+
// order preserving map used here to help test rollback
1223+
Map<Integer, String> data = new TreeMap<>();
1224+
data.put(7, "foo");
1225+
data.put(8, "bar");
1226+
data.put(9, null);
1227+
try {
1228+
sourceBuilder.putAllInt32ToStringField(data);
1229+
fail("allowed null string value");
1230+
} catch (NullPointerException expected) {
1231+
// Verify rollback of previously added values.
1232+
// They all go in or none do.
1233+
assertThat(sourceBuilder.getInt32ToStringFieldMap()).isEmpty();
1234+
}
1235+
}
1236+
1237+
@Test
1238+
public void testPutNullStringValue() throws Exception {
1239+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
1240+
1241+
try {
1242+
sourceBuilder.putInt32ToStringField(8, null);
1243+
fail("allowed null string value");
1244+
} catch (NullPointerException expected) {
1245+
assertNotNull(expected.getMessage());
1246+
}
1247+
}
12211248
}

java/core/src/test/java/com/google/protobuf/MapTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
import static com.google.common.truth.Truth.assertThat;
3434
import static com.google.common.truth.Truth.assertWithMessage;
35+
import static org.junit.Assert.assertNotNull;
36+
import static org.junit.Assert.fail;
3537

3638
import com.google.protobuf.Descriptors.Descriptor;
3739
import com.google.protobuf.Descriptors.EnumDescriptor;
@@ -50,6 +52,7 @@
5052
import java.util.HashMap;
5153
import java.util.List;
5254
import java.util.Map;
55+
import java.util.TreeMap;
5356
import org.junit.Test;
5457
import org.junit.runner.RunWith;
5558
import org.junit.runners.JUnit4;
@@ -464,6 +467,37 @@ public void testPutAll() throws Exception {
464467
assertMapValuesSet(destination.build());
465468
}
466469

470+
@Test
471+
public void testPutAllWithNullStringValue() throws Exception {
472+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
473+
474+
// order preserving map used here to help test rollback
475+
Map<Integer, String> data = new TreeMap<>();
476+
data.put(7, "foo");
477+
data.put(8, "bar");
478+
data.put(9, null);
479+
try {
480+
sourceBuilder.putAllInt32ToStringField(data);
481+
fail("allowed null string value");
482+
} catch (NullPointerException expected) {
483+
// Verify rollback of previously added values.
484+
// They all go in or none do.
485+
assertThat(sourceBuilder.getInt32ToStringFieldMap()).isEmpty();
486+
}
487+
}
488+
489+
@Test
490+
public void testPutNullStringValue() throws Exception {
491+
TestMap.Builder sourceBuilder = TestMap.newBuilder();
492+
493+
try {
494+
sourceBuilder.putInt32ToStringField(8, null);
495+
fail("allowed null string value");
496+
} catch (NullPointerException expected) {
497+
assertNotNull(expected.getMessage());
498+
}
499+
}
500+
467501
@Test
468502
public void testPutAllForUnknownEnumValues() throws Exception {
469503
TestMap source =

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
111111
(*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
112112
(*variables)["key_null_check"] =
113113
IsReferenceType(keyJavaType)
114-
? "if (key == null) { throw new java.lang.NullPointerException(); }"
114+
? "if (key == null) { throw new NullPointerException(\"map key\"); }"
115115
: "";
116116
(*variables)["value_null_check"] =
117-
IsReferenceType(valueJavaType)
118-
? "if (value == null) { throw new java.lang.NullPointerException(); }"
117+
valueJavaType != JAVATYPE_ENUM && IsReferenceType(valueJavaType)
118+
? "if (value == null) {\n"
119+
" throw new NullPointerException(\"map value\");\n"
120+
"}\n"
119121
: "";
120122
if (valueJavaType == JAVATYPE_ENUM) {
121123
// We store enums as Integers internally.
@@ -435,6 +437,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
435437
" $key_type$ key,\n"
436438
" $value_type$ value) {\n"
437439
" $key_null_check$\n"
440+
" $value_null_check$\n"
438441
" internalGetMutable$capitalized_name$().getMutableMap()\n"
439442
" .put(key, value);\n"
440443
" return this;\n"

update_file_lists.sh

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/bash -u
22

33
# This script copies source file lists from src/Makefile.am to cmake files.
44

@@ -50,12 +50,12 @@ MAKEFILE=src/Makefile.am
5050

5151
# Extract file lists from src/Makefile.am
5252
GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS)
53-
HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS)
54-
PUBLIC_HEADERS=$(sort_files $GZHEADERS $HEADERS)
53+
LIBPROTOBUF_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep -v /compiler/)
54+
LIBPROTOBUF_HEADERS=$(sort_files $GZHEADERS $LIBPROTOBUF_HEADERS)
5555
LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES)
5656
LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES)
5757
LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES)
58-
LIBPROTOC_HEADERS=$(get_header_files $MAKEFILE libprotoc_la_SOURCES)
58+
LIBPROTOC_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep /compiler/)
5959
LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs)
6060
PROTOS=$(get_proto_files $MAKEFILE protoc_outputs)
6161
PROTOS_BLACKLISTED=$(get_proto_files_blacklisted $MAKEFILE protoc_outputs)
@@ -98,7 +98,11 @@ set_cmake_value() {
9898
print \$0;
9999
len = split(values, vlist, \" \");
100100
for (i = 1; i <= len; ++i) {
101-
printf(\" %s%s\\n\", prefix, vlist[i]);
101+
printf(\" \");
102+
if (vlist[i] !~ /^\\\$/) {
103+
printf(\"%s\", prefix);
104+
}
105+
printf(\"%s\\n\", vlist[i]);
102106
}
103107
next;
104108
}
@@ -121,7 +125,7 @@ set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $CMAKE_PREFIX $LIBPRO
121125
set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_headers $CMAKE_PREFIX $LIBPROTOC_HEADERS
122126
set_cmake_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS
123127
set_cmake_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS_BLACKLISTED
124-
set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX $COMMON_TEST_SOURCES
128+
set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX '${common_lite_test_files}' $COMMON_TEST_SOURCES
125129
set_cmake_value $CMAKE_DIR/tests.cmake common_lite_test_files $CMAKE_PREFIX $COMMON_LITE_TEST_SOURCES
126130
set_cmake_value $CMAKE_DIR/tests.cmake tests_files $CMAKE_PREFIX $TEST_SOURCES
127131
set_cmake_value $CMAKE_DIR/tests.cmake non_msvc_tests_files $CMAKE_PREFIX $NON_MSVC_TEST_SOURCES
@@ -130,14 +134,14 @@ set_cmake_value $CMAKE_DIR/tests.cmake lite_arena_test_files $CMAKE_PREFIX $LITE
130134

131135
# Generate extract_includes.bat
132136
echo "mkdir include" > $EXTRACT_INCLUDES_BAT
133-
for INCLUDE in $PUBLIC_HEADERS $WKT_PROTOS; do
137+
for INCLUDE in $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS $WKT_PROTOS; do
134138
INCLUDE_DIR=$(dirname "$INCLUDE")
135139
while [ ! "$INCLUDE_DIR" = "." ]; do
136140
echo "mkdir include\\${INCLUDE_DIR//\//\\}"
137141
INCLUDE_DIR=$(dirname "$INCLUDE_DIR")
138142
done
139143
done | sort | uniq >> $EXTRACT_INCLUDES_BAT
140-
for INCLUDE in $PUBLIC_HEADERS $WKT_PROTOS; do
144+
for INCLUDE in $(sort_files $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS) $WKT_PROTOS; do
141145
WINPATH=${INCLUDE//\//\\}
142146
echo "copy \"\${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH\" include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT
143147
done
@@ -186,7 +190,7 @@ if [ -f "$BAZEL_BUILD" ]; then
186190
set_bazel_value $BAZEL_BUILD lite_test_protos "" $LITE_PROTOS
187191
set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS
188192
set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS
189-
set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_TEST_SOURCES
193+
set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_LITE_TEST_SOURCES $COMMON_TEST_SOURCES
190194
set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES
191195
set_bazel_value $BAZEL_BUILD non_msvc_test_srcs $BAZEL_PREFIX $NON_MSVC_TEST_SOURCES
192196
set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES

0 commit comments

Comments
 (0)