bugGNU Octave - Bugs: bug #62406, Common java classes (String,...

 
 

bug #62406: Common java classes (String, Number) do not have overloaded display routines as in Matlab

Submitter:  Glite <linuxbckp>
Submitted:  Tue 03 May 2022 10:56:30 AM UTC
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Wed 04 May 2022 05:30:29 PM UTC, comment #9: 

@Rik
Since MATLAB is totally a java-based software now and it could do many adapt to javaObject(), how about Octave just keep javaObject() incompatible with MATLAB?

Glite <linuxbckp>
Wed 04 May 2022 05:26:44 PM UTC, comment #8: 

Auto boxing/unboxing was a new feature when I learn java. That's really a long time.

Glite <linuxbckp>
Wed 04 May 2022 05:25:33 PM UTC, comment #7: 

The javaObject command is generic in the sense that it can create any object from any class in Java, and there are thousands of possible classes.  Hence, Octave applies a generic display strategy reporting what the variable is "Java object" and what class it is an instance of "java.lang.String".

Matlab does the same thing, in general.  For example, try

obj = javaObject ('java.lang.Object')

which creates a very, very basic Java object.  All Matlab reports is

obj =

java.lang.Object

Because java.lang.String is so common, and interconvertible with character arrays or strings in Matlab, they seem to have written a specific display routine for it.

Octave could do the same thing.  I'm not sure where, exactly, this would live.  Maybe in unboxing routines in ov-java.cc, or maybe in the display code.  Another strategy might be to call _java2mat_ and if that is successful then print the resulting octave_value using Octave's normal display routines.

Rik <rik5>
Project Administrator
Wed 04 May 2022 09:21:22 AM UTC, comment #6: 

It may have to do with boxing/unboxing, i.e. automatic conversion from Java objects to Octave variables and v.v.
There were some issues with that in the past, but it's a long time ago so the details escape me now.

Philip Nienhuis <philipnienhuis>
Project Member
Wed 04 May 2022 03:33:59 AM UTC, comment #5: 

And Octave can call toString() to return the string:

>> s.toString()

ans = 123

That's how java display the String string.

Glite <linuxbckp>
Wed 04 May 2022 03:27:30 AM UTC, comment #4: 

Yes, maybe MATLAB does some adapt with java.lang or more java package.
Should I test all java.lang.* classes on MATLAB to avoid duplicate bugs?

Glite <linuxbckp>
Wed 04 May 2022 02:49:21 AM UTC, comment #3: 

what i meant is that octave's default disp / display produces the less informative output, because it doesn't know enough about the object to display it any differently. Apparently Matlab does.  For octave to display it differently than the default, the object class would have to a method disp / display added to overload the default function and produce a different output.

Nicholas Jankowski <nrjank>
Project Member
Wed 04 May 2022 12:36:12 AM UTC, comment #2: 

MATLAB can disp() or display() the string too, but the real output is a bit different between disp() and display():

>> s=javaObject('java.lang.String', '123')


s =

123

>> disp(s)

123

>> display(s)


s =

123

>> disp(s.toUpperCase())

123

>> display(s.toUpperCase())

123

Those're about `123` and `s = 123`.

Glite <linuxbckp>
Tue 03 May 2022 03:35:47 PM UTC, comment #1: 

that looks like the default general display method for objects in octave.  looking at the methods for that object:

>> methods(s)
Methods for class java.lang.String:
String               copyValueOf          join                 startsWith
charAt               endsWith             lastIndexOf          subSequence
chars                equals               length               substring
codePointAt          equalsIgnoreCase     matches              toCharArray
codePointBefore      format               notify               toLowerCase
codePointCount       getBytes             notifyAll            toString
codePoints           getChars             offsetByCodePoints   toUpperCase
compareTo            getClass             regionMatches        trim
compareToIgnoreCase  hashCode             replace              valueOf
concat               indexOf              replaceAll           wait
contains             intern               replaceFirst
contentEquals        isEmpty              split

appears the object or its parent (assuming it's inheriting things) doesn't have the disp or display method defined (at least publicly).  that could be done to change the way it echoes the contents. String or array display is fairly straightforward, but depending on how variable the javaObject content can get, it could get a bit involved.

Nicholas Jankowski <nrjank>
Project Member
Tue 03 May 2022 10:56:30 AM UTC, original submission:  

A java.lang.String object on MATLAB will display the string after initialization, but Octave has different behavior.
Here is my code:

On MATLAB:

>> s=javaObject('java.lang.String', '123')


s =

123

On Octave:

>> s=javaObject('java.lang.String', '123')

s =

<Java object: java.lang.String>

Glite <linuxbckp>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by linuxbckp (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 project members can vote.

     

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-05-04 rik5 Severity3 - Normal 1 - Wish
    2022-05-04 rik5 StatusNone Confirmed
        Release7.1.0 dev
        SummaryjavaObject() java.lang.String Has Different Output with MATLAB Common java classes (String, Number) do not have overloaded display routines as in Matlab

    Back to the top


    Powered by Savane 3.9