Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
bf483dfb
Commit
bf483dfb
authored
Apr 07, 2017
by
Anuraag Agrawal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow unknown values for Map put*Value methods just like every other enum mutation method.
parent
efec7571
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
25 deletions
+8
-25
MapTest.java
java/core/src/test/java/com/google/protobuf/MapTest.java
+7
-16
JsonFormatTest.java
...rc/test/java/com/google/protobuf/util/JsonFormatTest.java
+1
-3
java_map_field.cc
src/google/protobuf/compiler/java/java_map_field.cc
+0
-3
java_map_field_lite.cc
src/google/protobuf/compiler/java/java_map_field_lite.cc
+0
-3
No files found.
java/core/src/test/java/com/google/protobuf/MapTest.java
View file @
bf483dfb
...
@@ -490,19 +490,13 @@ public class MapTest extends TestCase {
...
@@ -490,19 +490,13 @@ public class MapTest extends TestCase {
public
void
testPutForUnknownEnumValues
()
throws
Exception
{
public
void
testPutForUnknownEnumValues
()
throws
Exception
{
TestMap
.
Builder
builder
=
TestMap
.
newBuilder
()
TestMap
.
Builder
builder
=
TestMap
.
newBuilder
()
.
putInt32ToEnumFieldValue
(
0
,
0
)
.
putInt32ToEnumFieldValue
(
0
,
0
)
.
putInt32ToEnumFieldValue
(
1
,
1
);
.
putInt32ToEnumFieldValue
(
1
,
1
)
.
putInt32ToEnumFieldValue
(
2
,
1000
);
// unknown value.
try
{
builder
.
putInt32ToEnumFieldValue
(
2
,
1000
);
// unknown value.
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// expected
}
TestMap
message
=
builder
.
build
();
TestMap
message
=
builder
.
build
();
assertEquals
(
0
,
message
.
getInt32ToEnumFieldValueOrThrow
(
0
));
assertEquals
(
0
,
message
.
getInt32ToEnumFieldValueOrThrow
(
0
));
assertEquals
(
1
,
message
.
getInt32ToEnumFieldValueOrThrow
(
1
));
assertEquals
(
1
,
message
.
getInt32ToEnumFieldValueOrThrow
(
1
));
assertEquals
(
2
,
message
.
getInt32ToEnumFieldCount
());
assertEquals
(
1000
,
message
.
getInt32ToEnumFieldValueOrThrow
(
2
));
assertEquals
(
3
,
message
.
getInt32ToEnumFieldCount
());
}
}
public
void
testPutChecksNullKeysAndValues
()
throws
Exception
{
public
void
testPutChecksNullKeysAndValues
()
throws
Exception
{
...
@@ -1250,12 +1244,9 @@ public class MapTest extends TestCase {
...
@@ -1250,12 +1244,9 @@ public class MapTest extends TestCase {
builder
.
putInt32ToEnumFieldValue
(
1
,
TestMap
.
EnumValue
.
BAR
.
getNumber
());
builder
.
putInt32ToEnumFieldValue
(
1
,
TestMap
.
EnumValue
.
BAR
.
getNumber
());
assertEquals
(
assertEquals
(
TestMap
.
EnumValue
.
BAR
.
getNumber
(),
builder
.
getInt32ToEnumFieldValueOrThrow
(
1
));
TestMap
.
EnumValue
.
BAR
.
getNumber
(),
builder
.
getInt32ToEnumFieldValueOrThrow
(
1
));
try
{
builder
.
putInt32ToEnumFieldValue
(
1
,
-
1
);
builder
.
putInt32ToEnumFieldValue
(
1
,
-
1
);
assertEquals
(-
1
,
builder
.
getInt32ToEnumFieldValueOrThrow
(
1
));
fail
();
assertEquals
(
TestMap
.
EnumValue
.
UNRECOGNIZED
,
builder
.
getInt32ToEnumFieldOrThrow
(
1
));
}
catch
(
IllegalArgumentException
e
)
{
// expected
}
builder
.
putStringToInt32Field
(
"a"
,
1
);
builder
.
putStringToInt32Field
(
"a"
,
1
);
assertEquals
(
1
,
builder
.
getStringToInt32FieldOrThrow
(
"a"
));
assertEquals
(
1
,
builder
.
getStringToInt32FieldOrThrow
(
"a"
));
...
...
java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
View file @
bf483dfb
...
@@ -229,9 +229,7 @@ public class JsonFormatTest extends TestCase {
...
@@ -229,9 +229,7 @@ public class JsonFormatTest extends TestCase {
TestMap
.
Builder
mapBuilder
=
TestMap
.
newBuilder
();
TestMap
.
Builder
mapBuilder
=
TestMap
.
newBuilder
();
mapBuilder
.
putInt32ToEnumMapValue
(
1
,
0
);
mapBuilder
.
putInt32ToEnumMapValue
(
1
,
0
);
Map
<
Integer
,
Integer
>
mapWithInvalidValues
=
new
HashMap
<
Integer
,
Integer
>();
mapBuilder
.
putInt32ToEnumMapValue
(
2
,
12345
);
mapWithInvalidValues
.
put
(
2
,
12345
);
mapBuilder
.
putAllInt32ToEnumMapValue
(
mapWithInvalidValues
);
TestMap
mapMessage
=
mapBuilder
.
build
();
TestMap
mapMessage
=
mapBuilder
.
build
();
assertEquals
(
assertEquals
(
"{\n"
"{\n"
...
...
src/google/protobuf/compiler/java/java_map_field.cc
View file @
bf483dfb
...
@@ -417,9 +417,6 @@ GenerateBuilderMembers(io::Printer* printer) const {
...
@@ -417,9 +417,6 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $key_type$ key,
\n
"
" $key_type$ key,
\n
"
" $value_type$ value) {
\n
"
" $value_type$ value) {
\n
"
" $key_null_check$
\n
"
" $key_null_check$
\n
"
" if ($value_enum_type$.forNumber(value) == null) {
\n
"
" throw new java.lang.IllegalArgumentException();
\n
"
" }
\n
"
" internalGetMutable$capitalized_name$().getMutableMap()
\n
"
" internalGetMutable$capitalized_name$().getMutableMap()
\n
"
" .put(key, value);
\n
"
" .put(key, value);
\n
"
" return this;
\n
"
" return this;
\n
"
...
...
src/google/protobuf/compiler/java/java_map_field_lite.cc
View file @
bf483dfb
...
@@ -642,9 +642,6 @@ GenerateBuilderMembers(io::Printer* printer) const {
...
@@ -642,9 +642,6 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $key_type$ key,
\n
"
" $key_type$ key,
\n
"
" $value_type$ value) {
\n
"
" $value_type$ value) {
\n
"
" $key_null_check$
\n
"
" $key_null_check$
\n
"
" if ($value_enum_type$.forNumber(value) == null) {
\n
"
" throw new java.lang.IllegalArgumentException();
\n
"
" }
\n
"
" copyOnWrite();
\n
"
" copyOnWrite();
\n
"
" instance.getMutable$capitalized_name$ValueMap().put(key, value);
\n
"
" instance.getMutable$capitalized_name$ValueMap().put(key, value);
\n
"
" return this;
\n
"
" return this;
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment