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

RequestBodyInBytes is declared as non-nullable but can be null, causing compiler warnings #129

Closed
DmytroBevziuk opened this issue Nov 1, 2024 · 3 comments

Comments

@DmytroBevziuk
Copy link

DmytroBevziuk commented Nov 1, 2024

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?

@DmytroBevziuk DmytroBevziuk changed the title Make Elastic.Transport.ApiCallDetails.RequestBodyInBytes nullable RequestBodyInBytes is declared as non-nullable but can be null, causing compiler warnings Nov 1, 2024
@flobernd
Copy link
Member

flobernd commented Nov 1, 2024

Related to #72

@stevejgordon
Copy link
Collaborator

I will be fixing this particular case in an upcoming PR.

@stevejgordon
Copy link
Collaborator

Fixed in #131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants