Bug 844475

Summary: NPE in code completion on Array object
Product: [Other] RHQ Project Reporter: Libor Zoubek <lzoubek>
Component: CLIAssignee: Lukas Krejci <lkrejci>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: unspecified Docs Contact:
Priority: high    
Version: 4.4CC: hrupp, theute
Target Milestone: ---   
Target Release: RHQ 4.5.0   
Hardware: Unspecified   
OS: Unspecified   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-31 06:13:22 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Libor Zoubek 2012-07-30 15:54:06 EDT
Description of problem: I am getting NPE on codecompletion

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

How reproducible: always

Steps to Reproduce:
1.execute following steps in CLI:
var a = [1,2,3];
a.0.<pres tab for code completion>
Actual results:

	at org.rhq.scripting.javascript.JavascriptCompletor.getContextMatches(JavascriptCompletor.java:451)
	at org.rhq.scripting.javascript.JavascriptCompletor.contextComplete(JavascriptCompletor.java:203)
	at org.rhq.scripting.javascript.JavascriptCompletor.contextComplete(JavascriptCompletor.java:196)
	at org.rhq.scripting.javascript.JavascriptCompletor.complete(JavascriptCompletor.java:131)
	at org.rhq.enterprise.client.utility.CodeCompletionCompletorWrapper.complete(CodeCompletionCompletorWrapper.java:34)
	at jline.MultiCompletor.complete(MultiCompletor.java:53)
	at jline.ConsoleReader.complete(ConsoleReader.java:832)
	at jline.ConsoleReader.readLine(ConsoleReader.java:518)
	at jline.ConsoleReader.readLine(ConsoleReader.java:448)
	at org.rhq.enterprise.client.ClientMain.getUserInput(ClientMain.java:278)
	at org.rhq.enterprise.client.ClientMain$1.run(ClientMain.java:319)
	at java.lang.Thread.run(Thread.java:636)

Expected results:

Additional info: I think than code-completion is incorrect in the way then if you type a<tab> you get a. and pressing another tab you get a.{0,1,2} - indexes of array which is kinda invalid, you should get a[{0,1,2}] to access member of array.
Comment 1 Lukas Krejci 2013-01-02 06:14:06 EST
Our code completion is far from perfect and modifying it to differentiate between objects and arrays and offer different completion hints for each would only open up more questions for the missing features like, for example, the missing completions on the javascript's built-in functions and objects.

I.e. one could argue that both "." and "[" are valid "continuations" for an expression for all objects and that code completion on "a." should return all the built-in methods of the Array object, while completion on "a[" should return the quoted names of the built-in methods + the indices. To better understand the above, consider following examples:

var a = [1,2,3];

To avoid such complexity for which our code completion is just not ready, I've modified the completor to not offer the array indices as a completion hint on "a." type of expressions.

commit http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=af81247744ec551bd411435d2f3d0913bfe0ee95
Author: Lukas Krejci <lkrejci@redhat.com>
Date:   Wed Jan 2 11:57:44 2013 +0100

    [BZ 844475] - Don't try to do code completion on native javascript arrays.
Comment 2 Heiko W. Rupp 2013-08-31 06:13:22 EDT
Bulk close of old bugs in VERIFIED state.