Bug 604291

Summary: NPE thrown by TabularWriter when querying resources from CLI
Product: [Other] RHQ Project Reporter: John Sanda <jsanda>
Component: CLIAssignee: John Sanda <jsanda>
Status: CLOSED CURRENTRELEASE QA Contact: Sudhir D <sdharane>
Severity: medium Docs Contact:
Priority: high    
Version: 3.0.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 2.4 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-08-12 16:49:08 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 593121    

Description John Sanda 2010-06-15 19:22:53 UTC
Description of problem:
I ran into a NPE when trying to display a list of resources in the CLI when in interactive mode.



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


How reproducible:
Always with the specified criteria

Steps to Reproduce:
1. Have a running server with resources in your auto-discovery queue
2. Execute the following commands from the CLI prompt

$ login rhqadmin rhqadmin
$ criteria = ResourceCriteria();  // no need to specifiy new operator
$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);
$ resources = ResourceManager.findResourcesByCriteria(criteria);

3. An exception is throw before the results is printed to the console
  
Actual results:
java.lang.NullPointerException
	at org.rhq.enterprise.client.TabularWriter.shortVersion(TabularWriter.java:665)
	at org.rhq.enterprise.client.TabularWriter.print(TabularWriter.java:329)
	at org.rhq.enterprise.client.TabularWriter.print(TabularWriter.java:123)
	at org.rhq.enterprise.client.commands.ScriptCommand.execute(ScriptCommand.java:177)
	at org.rhq.enterprise.client.ClientMain.executePromptCommand(ClientMain.java:303)
	at org.rhq.enterprise.client.ClientMain$1.run(ClientMain.java:248)
	at java.lang.Thread.run(Thread.java:637)

Expected results:
Expected list of resources to be printed to the console.

Additional info:
This is not the first bug involving a NPE in TabularWriter that we have encountered. I am of the opinion that TabularWriter needs some significant refactoring; otherwise, I think we are going to see exceptions like this.

It should also be noted that this exception does not happen for all resource queries. For instance, the following does not result in an exception:

$ criteria = ResourceCriteria();
$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);
$ resources = ResourceManager.findResourcesByCriteria(criteria);

Comment 1 John Sanda 2010-06-18 15:20:41 UTC
There is a copy/paste error in the description. The CLI commands for reproducing the NPE are,

$ login rhqadmin rhqadmin
$ criteria = ResourceCriteria();  // no need to specifiy new operator
$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);
$ resources = ResourceManager.findResourcesByCriteria(criteria);

But not all queries generate the exception. For instance, the following commands do not result in a NPE,

$ login rhqadmin rhqadmin
$ criteria = ResourceCriteria();  // no need to specifiy new operator
$ resources = ResourceManager.findResourcesByCriteria(criteria);

Comment 2 Charles Crouch 2010-06-18 15:49:28 UTC
If this is a regression of 2.3.1 it needs to be Urgent priority

Comment 3 John Sanda 2010-06-18 16:06:14 UTC
I did not produce this exception with JON 2.3.1, so this must be a regression.

Comment 4 John Sanda 2010-06-23 04:27:02 UTC
Added null checks to avoid NPEs as well as added several unit tests; however, I think there is still a good bit of refactoring needed in this code. I will open a separate bug for that.

commit hash: e98a76091f74b19d89c6b5bac2ded52320a08df9

Comment 5 Sudhir D 2010-06-24 08:56:51 UTC
I tried this on jon-server-2.4.0.GA_QA build# 42, which was out just an hour back, and I'm still hitting NPE. 

rhqadmin.redhat.com:7080$ criteria = ResourceCriteria();                                
ResourceCriteria:
	inventoryManagerRequired: false
	         persistentClass: class org.rhq.core.domain.resource.Resource

rhqadmin.redhat.com:7080$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);

rhqadmin.redhat.com:7080$ resources = ResourceManager.findResourcesByCriteria(criteria);
java.lang.NullPointerException
	at org.rhq.enterprise.client.TabularWriter.shortVersion(TabularWriter.java:674)
	at org.rhq.enterprise.client.TabularWriter.print(TabularWriter.java:337)
	at org.rhq.enterprise.client.TabularWriter.print(TabularWriter.java:123)
	at org.rhq.enterprise.client.commands.ScriptCommand.execute(ScriptCommand.java:177)
	at org.rhq.enterprise.client.ClientMain.executePromptCommand(ClientMain.java:303)
	at org.rhq.enterprise.client.ClientMain$1.run(ClientMain.java:248)
	at java.lang.Thread.run(Thread.java:636)

I shall try it again on another latest build. So still keeping this with ON_QA.

Comment 6 Sudhir D 2010-07-01 08:55:51 UTC
Verified this against jon-server-2.4.0.GA_QA build# 44

rhqadmin.redhat.com:7080$ criteria = ResourceCriteria();
ResourceCriteria:
	inventoryManagerRequired: false
	         persistentClass: class org.rhq.core.domain.resource.Resource

rhqadmin.redhat.com:7080$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);

rhqadmin.redhat.com:7080$ resources = ResourceManager.findResourcesByCriteria(criteria);
no data

rhqadmin.redhat.com:7080$ 

I don't see NPE. Marking this bug as verified.

Comment 7 Corey Welton 2010-08-12 16:49:08 UTC
Mass-closure of verified bugs against JON.