Bug 604291 - NPE thrown by TabularWriter when querying resources from CLI
Summary: NPE thrown by TabularWriter when querying resources from CLI
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: CLI
Version: 3.0.0
Hardware: All
OS: Linux
high
medium vote
Target Milestone: ---
: ---
Assignee: John Sanda
QA Contact: Sudhir D
URL:
Whiteboard:
Keywords:
Depends On:
Blocks: jon-sprint11-bugs
TreeView+ depends on / blocked
 
Reported: 2010-06-15 19:22 UTC by John Sanda
Modified: 2010-08-12 16:49 UTC (History)
0 users

(edit)
Clone Of:
(edit)
Last Closed: 2010-08-12 16:49:08 UTC


Attachments (Terms of Use)

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@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 08:55:51 UTC
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 16:49:08 UTC
Mass-closure of verified bugs against JON.


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