Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash when object's contents is an empty list #1837

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/riak_object.erl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ find_bestobject(FetchedItems) ->

-spec is_head({ok, riak_object()}|riak_object()) -> boolean().
%% @private Check if an object is simply a head response
is_head({ok, #r_object{contents=[]}}) ->
false;
is_head({ok, #r_object{contents=Contents}}) ->
C0 = lists:nth(1, Contents),
case C0#r_content.value of
Expand Down Expand Up @@ -1676,6 +1678,17 @@ delete_hash(ObjOrClock) ->

-ifdef(TEST).

%% See https://github.com/basho/riak_kv/issues/1707
object_with_empty_contents_test() ->
B = <<"buckets_are_binaries">>,
K = <<"keys are binaries">>,

Contents = [],
O = #r_object{bucket=B,key=K,
contents=Contents,vclock=vclock:fresh()},

?assertEqual(false, is_head(O)).

object_test() ->
B = <<"buckets_are_binaries">>,
K = <<"keys are binaries">>,
Expand Down