Bug 1689175 - NullPointerException in case of wrong parameters in api calls via java sdk
Summary: NullPointerException in case of wrong parameters in api calls via java sdk
Alias: None
Product: ovirt-engine-sdk-java
Classification: oVirt
Component: Core
Version: 4.2.1
Hardware: Unspecified
OS: Unspecified
Target Milestone: ovirt-4.3.4
: 4.3.1
Assignee: Ondra Machacek
QA Contact: Lucie Leistnerova
Depends On:
Blocks: 1710395
TreeView+ depends on / blocked
Reported: 2019-03-15 11:01 UTC by suman.swaroop
Modified: 2019-06-11 06:24 UTC (History)
5 users (show)

Fixed In Version: java-ovirt-engine-sdk-4.3.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2019-06-11 06:24:03 UTC
oVirt Team: Infra
mperina: ovirt-4.3?
lleistne: testing_ack+

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
oVirt gerrit 98850 0 master MERGED Fix NPE in case of non existing ID 2019-03-26 07:26:46 UTC

Description suman.swaroop 2019-03-15 11:01:05 UTC
Description of problem:
Whenever we send a request to fetch any component detail like VM, datacenter
and if the id doesnot exist then the response throws a 404. In ovirt-engine-sdk HTTPConnection.java class send method, there is a check to verify whether the reponse header has content-type xml or not. for 404 response I am sure that this is not set and hence the getHeader function returns null which throws Null pointer exception. I suspect that all non-ok responses will lead to null pointer exception instead of some other proper error message.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:

Using ovirt engine java sdk,
This throws NUllpointerException

Actual results:
Failed to Send request, throws NullPointerException
Expected results:
I expect that proper Exceptions to be thrown in case of wrong Ids, or any other parameter being wrong in api calls. Or atleast a response object is returned with proper error codes and messages if possible

Additional info:

Comment 1 Ravi Nori 2019-03-18 13:33:20 UTC
If conn.systemService().vmsService().vmService("<vm-id>") return null because the vm does not exist for the id. A get on the vm would throw an NPE.

I suggest storing conn.systemService().vmsService().vmService("<vm-id>") in a variable and check if it is null before invoking a get on it.

Closing as not a bug

Comment 2 suman.swaroop 2019-03-18 13:36:56 UTC
That's what I am doing right now but would have expected a better response with proper error codes and messages.This makes debugging difficult.

Comment 3 suman.swaroop 2019-03-18 13:43:51 UTC
Last comment is somewhat not complete. conn.systemservice....vmService returns the vmservice, there is no api call involved yet and it is never null. The moment a api call is made using get method of the service, the response does not have content-type field then the send function in HttpConnection class throws NPE if vm id does not exist. proper checks should have been there in the send request.

Comment 4 Lucie Leistnerova 2019-06-06 20:25:43 UTC
running system services with non existing ID throws exception:
Error: HTTP response code is "404". HTTP response message is "Not Found"

Verified in java-ovirt-engine-sdk4-4.3.1-1.el7ev.noarch

Comment 5 Sandro Bonazzola 2019-06-11 06:24:03 UTC
This bugzilla is included in oVirt 4.3.4 release, published on June 11th 2019.

Since the problem described in this bug report should be
resolved in oVirt 4.3.4 release, it has been closed with a resolution of CURRENT RELEASE.

If the solution does not work for you, please open a new bug report.

Note You need to log in before you can comment on or make changes to this bug.