Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 321378

Summary: [BrowserFunction] fails if empty array is returned
Product: [RT] RAP Reporter: Philipp Leusmann <leusmann>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 1.3   
Target Milestone: 1.4 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Philipp Leusmann CLA 2010-07-30 12:34:53 EDT
Build Identifier: 

When a BrowserFunction returns an empty array, org.eclipse.swt.internal.browser.browserkit.BrowserLCA.toJson(Object, boolean) encodes it as "][".

as a patch, the concerned if-block in said method could be:

else if (object.getClass().isArray())
        {
            Object[] array = (Object[]) object;
            result.append("[");
            for (int i = 0; i < array.length; i++)
            {
                result.append(toJson(array[i], false));
            }
            if (',' == result.charAt(result.length() - 1))
            {
                // insert ']' before last ','
                result.insert(result.length() - 1, "]");
            }
            else
            {
                // special handling for empty array
                result.append("],");
            }
        }


Also there are two related topics:

1) The method does not handle collections. An adequate addition would be

else if (object instanceof Collection)
        {
            result.append(toJson(((Collection) object).toArray(), false));
        }

2) What is the deleteLastChar-argument good for? Wouldn't it be sufficient to check, if the last character of the returned string is ',' and remove it, if needed?

Reproducible: Always
Comment 1 Ivan Furnadjiev CLA 2010-08-09 04:23:42 EDT
Fixed in CVS HEAD. Are you sure that SWT supports Collection in the result object? If yes, please open a separate bug with a snippet to reproduce it.
Comment 2 Philipp Leusmann CLA 2010-08-09 04:38:32 EDT
Ivan, I don't know if SWT supports collections and to not really have an opportunity to look it up.
I just thought it would be a natural extension.
Comment 3 Ivan Furnadjiev CLA 2010-08-09 04:59:35 EDT
I've just checked it in SWT (Snippet307.java) and exception is thrown in case of Collection - "Return value not valid".