bugGNU Octave - Bugs: bug #41931, listdlg returns Java object int[]...

 
 

bug #41931: listdlg returns Java object int[] rather than an integer

Submitter:  Rik <rik5>
Submitted:  Sat 22 Mar 2014 04:05:12 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 22 Mar 2014 07:07:45 PM UTC, comment #2: 

I modified the patch to also return an empty matrix, rather than an empty cell list, if the listdlg fails.  This matches Matlab behavior.  I checked in the changeset on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/51a0d1c1023c).

Rik <rik5>
Group administrator
Sat 22 Mar 2014 03:09:49 PM UTC, comment #1: 

This goes back to at least OF Java package 1.2.8

With octave-3.4.3 & 3.6.4 (both MinGW):
octave:1> [sel, ok] = listdlg ("Liststring", {"One", "Two", "Three"})
...<selecting "Two", clicking OK>
sel =

<Java object: int[]>

ok =  1
octave:2>  {"One", "Two", "Three"}(sel(1))
ans =
{
  [1,1] = Two
}
octave:3> numel (sel)
ans =  1
octave:4> [sel, ok] = listdlg ("ListString", {"One", "Two", "Three"}, "SelectionMode", "Multiple")
...<selecting "One" and "Three", clicking OK>
sel =

<Java object: int[]>

ok =  1
octave:5> numel (sel)
ans =  2
octave:6>  {"One", "Two", "Three"}(sel(1))
ans =
{
  [1,1] = One
}
octave:7>  {"One", "Two", "Three"}(sel(2))
ans =
{
  [1,1] = Three
}
-verbatim-

It isn't straightforward to cast (box) sel into an Octave class:


octave:8> javamethods (sel)

{
  [1,1] = void wait(long) throws java.lang.InterruptedException
  [1,2] = void wait() throws java.lang.InterruptedException
  [1,3] = void wait(long, int) throws java.lang.InterruptedException
  [1,4] = boolean equals(java.lang.Object)
  [1,5] = java.lang.String toString()
  [1,6] = int hashCode()
  [1,7] = java.lang.Class getClass()
  [1,8] = void notify()
  [1,9] = void notifyAll()
}


but as sel can be used for indexing, something along the lines of:
tmp = zeros (numel (sel))
for ii=1:numel (sel)
tmp(ii) = sel(ii);
endfor

gives the desired pointers into ListString.

BTW, the example in listdlg.m isn't at variance with the the bug report and the above observations. Nowhere is it literally stated that sel is an Octave integer. But obviously that is what unwary users would expect.


Another observation:
The actual listing of "One Two Three" doesn't appear on screen unless ListString is in camelcase; IOW the list of choices is empty. Similar holds for other key names.
I'd rather prefer case-insensitive key names. Easily done by morphing the strcmp calls into strcmpi.


Changeset attached for both "issues"


(file #31005)

Philip Nienhuis <philipnienhuis>
Group Member
Sat 22 Mar 2014 04:05:12 AM UTC, original submission:  

listdlg, when running in cli-mode, executes Java code to display a list.  It is supposed to return an integer which is the 1-based index of the item selected.  Instead, it is returning an actual Java Object.


sel = listdlg ('ListString', {'a','b','c'})
sel =

<Java object: int[]>


Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #31005:  listdlg_41931.cs added by philipnienhuis (2KiB - text/x-csharp)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-03-22 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2014-03-22 philipnienhuis StatusNone Patch Submitted
    2014-03-22 philipnienhuis Attached File- Added listdlg_41931.cs, #31005

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code