Skip to content

Commit bb0bb81

Browse files
committed
Bulk selector should not be nullable, fix NRE in DebugInformation
Cherry-pick of #2054
1 parent 05dec83 commit bb0bb81

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/Nest/CommonAbstractions/Response/ResponseBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public string DebugInformation
4343
get
4444
{
4545
var sb = new StringBuilder();
46-
sb.Append($"{(!IsValid ? "Inv" : "V")}alid NEST response built from a ");
47-
sb.AppendLine(ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this");
46+
sb.Append($"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a ");
47+
sb.AppendLine(this.ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this");
4848
if (!this.IsValid) this.DebugIsValid(sb);
49-
ResponseStatics.DebugInformationBuilder(ApiCall, sb);
49+
if (this.ApiCall != null) ResponseStatics.DebugInformationBuilder(ApiCall, sb);
5050
return sb.ToString();
5151
}
5252
}
5353
protected virtual void DebugIsValid(StringBuilder sb) { }
5454

55-
public override string ToString() => $"{(!IsValid ? "Inv" : "V")}alid NEST response built from a {this.ApiCall?.ToString().ToCamelCase()}";
55+
public override string ToString() => $"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a {this.ApiCall?.ToString().ToCamelCase()}";
5656

5757
}
5858
}

src/Nest/Document/Multiple/Bulk/BulkResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class BulkResponse : ResponseBase, IBulkResponse
1919
public override bool IsValid => base.IsValid && !this.Errors && !this.ItemsWithErrors.HasAny();
2020
protected override void DebugIsValid(StringBuilder sb)
2121
{
22+
if (this.Items == null) return;
2223
sb.AppendLine($"# Invalid Bulk items:");
2324
foreach(var i in Items.Select((item, i) => new { item, i}).Where(i=>!i.item.IsValid))
2425
sb.AppendLine($" operation[{i.i}]: {i.item}");

src/Nest/Document/Multiple/Bulk/ElasticClient-Bulk.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Nest
77
public partial interface IElasticClient
88
{
99
/// <summary>
10-
/// The bulk API makes it possible to perform many index/delete operations in a single API call.
10+
/// The bulk API makes it possible to perform many index/delete operations in a single API call.
1111
/// This can greatly increase the indexing speed.
1212
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
1313
/// </summary>
@@ -28,23 +28,23 @@ public partial interface IElasticClient
2828
public partial class ElasticClient
2929
{
3030
/// <inheritdoc/>
31-
public IBulkResponse Bulk(IBulkRequest request) =>
31+
public IBulkResponse Bulk(IBulkRequest request) =>
3232
this.Dispatcher.Dispatch<IBulkRequest, BulkRequestParameters, BulkResponse>(
3333
request, this.LowLevelDispatch.BulkDispatch<BulkResponse>
3434
);
3535

3636
/// <inheritdoc/>
37-
public IBulkResponse Bulk(Func<BulkDescriptor, IBulkRequest> selector = null) =>
37+
public IBulkResponse Bulk(Func<BulkDescriptor, IBulkRequest> selector) =>
3838
this.Bulk(selector.InvokeOrDefault(new BulkDescriptor()));
3939

4040
/// <inheritdoc/>
41-
public Task<IBulkResponse> BulkAsync(IBulkRequest request) =>
41+
public Task<IBulkResponse> BulkAsync(IBulkRequest request) =>
4242
this.Dispatcher.DispatchAsync<IBulkRequest, BulkRequestParameters, BulkResponse, IBulkResponse>(
4343
request, this.LowLevelDispatch.BulkDispatchAsync<BulkResponse>
4444
);
4545

4646
/// <inheritdoc/>
47-
public Task<IBulkResponse> BulkAsync(Func<BulkDescriptor, IBulkRequest> selector = null) =>
47+
public Task<IBulkResponse> BulkAsync(Func<BulkDescriptor, IBulkRequest> selector) =>
4848
this.BulkAsync(selector.InvokeOrDefault(new BulkDescriptor()));
4949
}
50-
}
50+
}

0 commit comments

Comments
 (0)