Bug 604291 - NPE thrown by TabularWriter when querying resources from CLI
NPE thrown by TabularWriter when querying resources from CLI
Status: CLOSED CURRENTRELEASE
Product: RHQ Project
Classification: Other
Component: CLI (Show other bugs)
3.0.0
All Linux
high Severity medium (vote)
: ---
: ---
Assigned To: John Sanda
Sudhir D
:
Depends On:
Blocks: jon-sprint11-bugs
  Show dependency treegraph
 
Reported: 2010-06-15 15:22 EDT by John Sanda
Modified: 2010-08-12 12:49 EDT (History)
0 users

See Also:
Fixed In Version: 2.4
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-08-12 12:49:08 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 John Sanda 2010-06-15 15:22:53 EDT
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 11:20:41 EDT
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 11:49:28 EDT
If this is a regression of 2.3.1 it needs to be Urgent priority
Comment 3 John Sanda 2010-06-18 12:06:14 EDT
I did not produce this exception with JON 2.3.1, so this must be a regression.
Comment 4 John Sanda 2010-06-23 00:27:02 EDT
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 04:56:51 EDT
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@dhcp6-150.pnq.redhat.com:7080$ criteria = ResourceCriteria();                                
ResourceCriteria:
	inventoryManagerRequired: false
	         persistentClass: class org.rhq.core.domain.resource.Resource

rhqadmin@dhcp6-150.pnq.redhat.com:7080$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);

rhqadmin@dhcp6-150.pnq.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 04:55:51 EDT
Verified this against jon-server-2.4.0.GA_QA build# 44

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

rhqadmin@dhcp6-150.pnq.redhat.com:7080$ criteria.addFilterInventoryStatus(InventoryStatus.NEW);

rhqadmin@dhcp6-150.pnq.redhat.com:7080$ resources = ResourceManager.findResourcesByCriteria(criteria);
no data

rhqadmin@dhcp6-150.pnq.redhat.com:7080$ 

I don't see NPE. Marking this bug as verified.
Comment 7 Corey Welton 2010-08-12 12:49:08 EDT
Mass-closure of verified bugs against JON.

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