-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
Issue: RequestBodyInBytes is declared as non-nullable but can be null, causing compiler warnings
Description: I’m encountering an issue with the ElasticsearchClientSettings where the RequestBodyInBytes property is declared as a non-nullable byte[], but it can actually be null in certain cases. For example, when calling DeleteAsync, the RequestBodyInBytes is null because there’s no request body.
ElasticsearchClientSettings configuration:
var settings = new ElasticsearchClientSettings(new Uri(elasticsearchOptions.Url))
.CertificateFingerprint(fingerprint)
.Authentication(new BasicAuthentication(elasticsearchOptions.Username, elasticsearchOptions.Password))
.EnableDebugMode(cd =>
{
var requestBody = string.Empty;
if (cd.RequestBodyInBytes != null && cd.RequestBodyInBytes.Length > 0)
{
requestBody = Encoding.Default.GetString(cd.RequestBodyInBytes);
}
logger.LogDebug("Debug info: {debugInfo}. Request: {request}", cd.DebugInformation, requestBody);
})
.PrettyJson();
return new ElasticsearchClient(settings);This part:
if (cd.RequestBodyInBytes != null && cd.RequestBodyInBytes.Length > 0)
{
requestBody = Encoding.Default.GetString(cd.RequestBodyInBytes);
}returns the warning "Expression is always true according to nullable reference types' annotations".
Is it possible to make this type nullable or don't assign null values?
Metadata
Metadata
Assignees
Labels
No labels