Bug 808629 - Internal server for request GET /api/hosts in JSON format
Summary: Internal server for request GET /api/hosts in JSON format
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: oVirt
Classification: Retired
Component: ovirt-engine-api
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: 3.1
Assignee: Ori Liel
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-03-30 22:01 UTC by Adam Litke
Modified: 2012-08-09 07:59 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-08-09 07:59:07 UTC
oVirt Team: ---


Attachments (Terms of Use)

Description Adam Litke 2012-03-30 22:01:28 UTC
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 17:13:25 UTC
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 08:56:34 UTC
The change has been merged.

Comment 3 Itamar Heim 2012-08-09 07:59:07 UTC
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.