Bug 808629 - Internal server for request GET /api/hosts in JSON format
Internal server for request GET /api/hosts in JSON format
Status: CLOSED CURRENTRELEASE
Product: oVirt
Classification: Community
Component: ovirt-engine-api (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: 3.1
Assigned To: Ori Liel
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-30 18:01 EDT by Adam Litke
Modified: 2012-08-09 03:59 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-08-09 03:59:07 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Adam Litke 2012-03-30 18:01:28 EDT
Description of problem:
Attempting to retrieve the hosts collection in JSON format causes an internal server error:

2012-03-30 16:55:55,882 ERROR [org.jboss.resteasy.core.SynchronousDispatcher] (http--0.0.0.0-8080-4) Failed executing GET /hosts: org.jboss.resteasy.spi.WriterException: org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.ovirt.engine.api.model.Hosts["hosts"]->java.util.ArrayList[0]->org.ovirt.engine.api.model.Host["storageManager"])
        at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:262) [resteasy-jaxrs-2.2.3.GA.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:579) [resteasy-jaxrs-2.2.3.GA.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:500) [resteasy-jaxrs-2.2.3.GA.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.2.3.GA.jar:]
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.2.3.GA.jar:]
...

Version-Release number of selected component (if applicable):
ovirt-engine git: 7353b27de3b182f1f6c511cbc9f1412743a377bb

How reproducible:
Always


Steps to Reproduce:
1. Use REST Client for Firefox
2. Add request header: 'Accept: application/json'
3. Request URL /api/hosts
  
Actual results:
Internal server error:

HTTP Status 500 - org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.ovirt.engine.api.model.Hosts["hosts"]->java.util.ArrayList[0]->org.ovirt.engine.api.model.Host["storageManager"])

type Status report

message org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.ovirt.engine.api.model.Hosts["hosts"]->java.util.ArrayList[0]->org.ovirt.engine.api.model.Host["storageManager"])

description The server encountered an internal error (org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.ovirt.engine.api.model.Hosts["hosts"]->java.util.ArrayList[0]->org.ovirt.engine.api.model.Host["storageManager"])) that prevented it from fulfilling this request.
JBoss Web/7.0.3.Final

Expected results:
A JSON representation of the hosts collection.

Additional info:
Comment 1 Juan Hernández 2012-04-11 13:13:25 EDT
The reason for this is that the StorageManager type in the RESTAPI XSD doesn't have a default value for the priority attribute. The code generated by the JAXB compiler looks like this:

  protected Integer priority = null;

  public int getPriority() {
    return priority;
  }

The Jackson JSON serializer creates instances of this objects to get default values and the implicit unboxing of the priority attribute generates the NPE. Adding the default value the generated code is this:

  protected Integer priority = null;

  public int getPriority() {
    if (priority == null) {
      return  0;
    } else {
      return priority;
    }
  }

Proposed patch to fix the issue is available here:

http://gerrit.ovirt.org/3476
Comment 2 Juan Hernández 2012-04-17 04:56:34 EDT
The change has been merged.
Comment 3 Itamar Heim 2012-08-09 03:59:07 EDT
closing ON_QA bugs as oVirt 3.1 was released:
http://www.ovirt.org/get-ovirt/

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