Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

ClassCastException handling a 204 response with empty body #126

@hummer-hpe

Description

@hummer-hpe

Steps to reproduce

What steps can reproduce the defect?
Please share the setup, sample project, version of Java etc.

Occasionally, when querying for azure utilization by subscription by customer, the PartnerServiceClient.handleResponse method throws a ClassCastException. This occurs when a 204 response is handled with an empty body. Here's an example query:

ResourceCollection<AzureUtilizationRecord> records = api.getCustomers()
                     .byId(customerId)
                     .getSubscriptions()
                     .byId(subscription.getId())
                     .getUtilization()
                     .getAzure()
                     .query(startTime, endTime, AzureUtilizationGranularity.HOURLY, true, 1000);

Here's where PartnerServiceClient.handleResponse triggers the exception:

response = httpClient().newCall(request).execute();
if(response.isSuccessful())
{
	responseBody = response.body().string();
	if(StringHelper.isNullOrEmpty(responseBody))
	{
		value = (T)response;  // <--- THIS CAUSES ClassCastException
	}
	else
	{
		value = getJsonConverter().readValue(responseBody, responseType);
	}
	response.close();
	return value; 
}

Expected behavior

Share the expected output

I'd expect a null to be returned, or some form of not found exception to be thrown, but never a class cast exception, especially for a 204 response, which is defined as not having a response body.

Actual behavior

What is the behavior observed?

ClassCastException is thrown.

Diagnostic logs

Please share test platform diagnostics logs.
The logs may contain test assembly paths, kindly review and mask those before sharing.

Environment

Please share additional details about your environment.
Version

Observed this behavior with both versions 1.13.2 and 1.15.3, and I see that the latest code on master (1.15.4) will do the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions