bugGNU Octave - Bugs: bug #46200, octave automatically converts java...

 
 

bug #46200: octave automatically converts java strings into char arrays

Submitter:  Carnë Draug <carandraug>
Submitted:  Tue 13 Oct 2015 12:51:00 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Duplicate Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 27 Jun 2018 10:01:11 AM UTC, comment #3: 

This seems to be a duplicate of bug #42701.

Markus Mützel <mmuetzel>
Group administrator
Tue 13 Oct 2015 08:05:22 PM UTC, comment #2: 

This afternoon I did just that, and indeed in your first example the result remains to be a Java object.

ML r2014a says about your second example (copied by typing over as I can't copy/paste from remote desktop):

>> format compact
jarr = javaArray ('java.lang.String', 2, 2)
jarr =

java.lang.String[][]:
    []    []
    []    []

>> jarr(1,2) = 'hello world'
Assignment of char to Java arrays is not allowed
jar12 = javaObject ('java.lang.string', 'hello world')
jar12 =
hello world
jar(1,2) = jar12
jarr =

java.lang.String[][]:
    []    'hello world'
    []               []


Philip Nienhuis <philipnienhuis>
Group Member
Tue 13 Oct 2015 03:29:15 PM UTC, comment #1: 

Need someone with Matlab and some tests cases.  I think there may be a distinction between returning the generic javaObject class, which then gets queried by Matlab and converted if necessary, and returning a specific object from a given class.

Otherwise, you it would be next to impossible to actually create a java.lang.String object because it would always be auto-converted.

As an example, what does Matlab do for


jstr = javaObject ('java.lang.String', 'Hello World')
isjava (jstr)


My guess is that this remains an object, not converted to char.

On the other hand, the following code does do auto-conversion.  Presumably, because a Java array is an array of the generic java.lang.Object type


octave:17> jarr = javaArray ('java.lang.String', 2,2)
jarr =

<Java object: java.lang.String[][]>

octave:18> jarr(1,2) = 'hello world'
jarr =

<Java object: java.lang.String[][]>

octave:19> % Now index into array
octave:19> jarr(1,2)
ans = hello world



Rik <rik5>
Group administrator
Tue 13 Oct 2015 12:51:00 PM UTC, original submission:  

Octave automatically converts specific java objects into Octave data types as Matlab supposedly does.  This includes converting a java.lang.String into a char array.  According to Matlab documentation http://uk.mathworks.com/help/matlab/matlab_external/handling-data-returned-from-a-java-method.html#f61197

> When a method call returns data of type java.lang.Object, MATLAB converts its value, depending on its actual type, according to the following table.


However, it seems that our interpretation of Matlab documentation was incorrect (see https://github.com/openmicroscopy/bioformats/pull/2017#discussion_r41634730 for the origin of this)


>> version = loci.formats.FormatTools.VERSION;
>> class(version)

ans =

java.lang.String


Could it be that Matlab documentation meant that it performs an implicit conversion to char when required and not as soon as the java method returns? I don't know what's the way to Matlab compatibility.

Carnë Draug <carandraug>
Group Member

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by carandraug (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-06-27 mmuetzel StatusNone Duplicate
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code