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
4aecb2b6
Commit
4aecb2b6
authored
May 01, 2014
by
Jan-Willem Maarse
Committed by
Gerrit Code Review
May 01, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Fix NPE when clearing an extension in nano protos"
parents
a2724e7c
b24fdd47
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
Extension.java
java/src/main/java/com/google/protobuf/nano/Extension.java
+1
-1
NanoTest.java
java/src/test/java/com/google/protobuf/NanoTest.java
+14
-0
No files found.
java/src/main/java/com/google/protobuf/nano/Extension.java
View file @
4aecb2b6
...
...
@@ -268,7 +268,7 @@ public class Extension<M extends ExtendableMessageNano<M>, T> {
// After deletion or no-op addition (due to 'value' being an array of empty or
// null-only elements), unknownFields may be empty. Discard the ArrayList if so.
return
(
unknownFields
.
size
()
==
0
)
?
null
:
unknownFields
;
return
(
unknownFields
==
null
||
unknownFields
.
isEmpty
()
)
?
null
:
unknownFields
;
}
protected
UnknownFieldData
writeData
(
Object
value
)
{
...
...
java/src/test/java/com/google/protobuf/NanoTest.java
View file @
4aecb2b6
...
...
@@ -2910,6 +2910,20 @@ public class NanoTest extends TestCase {
assertTrue
(
Arrays
.
equals
(
enums
,
message
.
getExtension
(
RepeatedExtensions
.
repeatedEnum
)));
}
public
void
testNullExtensions
()
throws
Exception
{
// Check that clearing the extension on an empty message is a no-op.
Extensions
.
ExtendableMessage
message
=
new
Extensions
.
ExtendableMessage
();
message
.
setExtension
(
SingularExtensions
.
someMessage
,
null
);
assertEquals
(
0
,
MessageNano
.
toByteArray
(
message
).
length
);
// Check that the message is empty after setting and clearing an extension.
AnotherMessage
another
=
new
AnotherMessage
();
message
.
setExtension
(
SingularExtensions
.
someMessage
,
another
);
assertTrue
(
MessageNano
.
toByteArray
(
message
).
length
>
0
);
message
.
setExtension
(
SingularExtensions
.
someMessage
,
null
);
assertEquals
(
0
,
MessageNano
.
toByteArray
(
message
).
length
);
}
public
void
testUnknownFields
()
throws
Exception
{
// Check that we roundtrip (serialize and deserialize) unrecognized fields.
AnotherMessage
message
=
new
AnotherMessage
();
...
...
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