bugGNU Octave - Bugs: bug #60123, method methods and ismethod...

 
 

bug #60123: method methods and ismethod silently changed: includes constructors now

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Fri 26 Feb 2021 09:35:45 AM UTC
   
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  None Assigned to:  None
Originator Name:  Reissner Open/Closed:  * Open
Release:  * 6.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 01 Mar 2021 10:05:45 PM UTC, comment #16: 

In methods.m, Octave displays the result of calling


javaMethod ("getMethods", "org.octave.ClassHelper", OBJ);


in which OBJ is either a Java object or the name of a Java class.  The org.octave.ClassHelper method is here:

http://hg.savannah.gnu.org/hgweb/octave/file/9bbe11da0c38/scripts/java/org/octave/ClassHelper.java#l169

If there should be more information about the methods when "-full" is given, can you provide a patch?

John W. Eaton <jwe>
Group administrator
Mon 01 Mar 2021 07:16:41 PM UTC, comment #15: 

John, I never treated anyone here without respect.
I am sorry, i am responsible for some shift in focus in this report.

Back to documentation:

    List the names of the public methods for the object OBJ or the
     named class CLASSNAME.


better to mention constructors,
as in older versions there was a function `constructors`,
believe it or not.
Suggestion:

    List the names of the public methods and constructors
    for the object OBJ or the named class CLASSNAME.

At least this is so for java.
It is also so for matlab, just a note.


If the optional argument "-full" is given then Octave returns full
     method signatures which include output type, name of method, and
     the number and type of inputs.


At least for java also checked exceptions belong to the signature and they are given also.


Well belive it or not, i saw octave display more than that.
I remember final and static mofifier at least.
As mentioned below, matlab displays more, more modifiers
and a comment whether the method is inherited.
If you need deteils, find below in links within some of my comment.
Also for java there is a defined set of modifiers belonging to the signature.
Of course, public is not displayed as methods displays public mehtods and constructors only anyway.
But this goes beyond documentation.

Ernst Reissner <ernstreissner>
Mon 01 Mar 2021 03:45:32 PM UTC, comment #14: 

Ernst: We have never defined Octave as a "clone" of Matlab.  We aim for compatibility where it makes sense.  You might find it easier to work with us if you treat us as fellow volunteer developers who are doing our best to make Octave better (which we are) instead of as adversaries who are working to break things just to frustrate you (which we are not).

John W. Eaton <jwe>
Group administrator
Mon 01 Mar 2021 07:17:50 AM UTC, comment #13: 

To get this back on track, I'll repeat what I wrote in comment #6:
Please, propose better wording for the documentation if you think it is currently incomplete.

Markus Mützel <mmuetzel>
Group administrator
Sun 28 Feb 2021 11:46:02 PM UTC, comment #12: 

https://www.mathworks.com/help/matlab/ref/methods.html
shows how it is meant:
methods('java.lang.String')
returns just names of constructor(s) and methods.
If two (constructors or) functions have the same names (but differ e.g. in arguments), only one name is given.

In contrast, methods('java.lang.String','full') shows method signatures.
It is ugly, but for that variant,
the result is given somewhere else:
https://www.mathworks.com/help/matlab/matlab_external/java-method-information.html
-verbatim-
Methods for class java.awt.Dimension:
Dimension()
Dimension(java.awt.Dimension)
Dimension(int,int)
java.lang.Class getClass()  % Inherited from java.lang.Object
int hashCode()  % Inherited from java.lang.Object
boolean equals(java.lang.Object)
java.lang.String toString()
void notify()  % Inherited from java.lang.Object
void notifyAll()  % Inherited from java.lang.Object
void wait(long) throws java.lang.InterruptedException
   % Inherited from java.lang.Object
void wait(long,int) throws java.lang.InterruptedException
   % Inherited from java.lang.Object
void wait() throws java.lang.InterruptedException
   % Inherited from java.lang.Object
java.awt.Dimension getSize()
void setSize(java.awt.Dimension)
void setSize(int,int)


You can see, that now the following is added:
- parameter list
- throws clause for checked exceptions,
- return type,
- inheritance information
- I think, also modifiers like static, final, .... (no access)
Again, the constructors are treated as methods.

Ernst Reissner <ernstreissner>
Sun 28 Feb 2021 11:37:23 PM UTC, comment #11: 

As for javachk('jvm') is fully what we need
and yes it is matlab conform. No change needed.

The same for version('-java')
which can be checked in https://www.mathworks.com/help/matlab/ref/version.html
There is just an example no formal specification:

ans =
'Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'

In fact, it is more than version, it comprises also vendor information.

With a little regexp one can find the version:
it is behind 'Java ' and in front of ' with'.
I think, even, it is less than that, it is just 1.8.0,
but we must distinguish specification version (1.8.0)
and runtime version.

But this is really thread drift.

Ernst Reissner <ernstreissner>
Sun 28 Feb 2021 09:58:45 PM UTC, comment #10: 

[Thread drift alert]
That further Java development in Octave is "refused" may be perceived that way but I think there's more nuance behind the scenes.

As an example, we have had issues in the past with Java JVMs apparently fiddling with CPU flags which somehow seemed to affect numerical results elsewhere in Octave's code base. Maybe an extreme example, but bearing such things in mind I can follow the core devs being reluctant to adapt changes to the Java subsystem if the consequences aren't fully understood.
Plus, we're all volunteers and all lack time and as a consequence we pick up the things we're most familiar with. Again, as it happens Java is not in the lucky collection of subjects.

As to javachk and version:

javachk.m (that I wrote) needs to stay Matlab-compatible; same for usejava.m. Matlab's output tmplate for these allows no easy way to return the version.
But I'll post s/th in bug #60058.

Philip Nienhuis <philipnienhuis>
Group Member
Sun 28 Feb 2021 01:11:54 PM UTC, comment #9: 

@philip:
you are absolutely right, with all you say.
I think, java is used from within matlab much more than from octave.
On the other hand, it defines itself to be a clone
and so it shall have the according capabilites.

With octave i am not really happy as regards java,
because further development is mostly refused.

You talk about version hell.
First of all, octave offers version("-java") to find out the version.
If you write a package you can test on that.
But it is not really well supported:
documentation for that is bad, although function is as documented for matlab
and seemingly it is distracting for octave developers
to add  java dependency on the Description file,
which is the only way to make the package manager manage versions.

By the way, also there is javachk('jvm')
which returns whether there is a jvm available at all.
So it would be easy to put it all together
and check version.

So summarizing, octave has all basic means to work properly with java versions,
but they are not really used .


What i am missing is, to be able to configure which of my java vms i want to use.

Ernst Reissner <ernstreissner>
Sat 27 Feb 2021 12:16:00 PM UTC, comment #8: 

@Ernst:
You're not quite the only Java user here, we occasionally get bug reports relating to Java from other users than you and in the io package (that I maintain) there's a lot of Java based code (TBH, how many people would be using that is beyond me:-) ).

One big difference is is that AFAIK the entire Matlab GUI is based on Java (at least, it used to be) so Java is a much more natural choice to fall back on with Matlab.
OTOH in my experience Matlab's dependency on Java can be a PITA as well, as it heavily relies on its own bundled JRE. E.g., it can be hard to invoke methods in newer class libs outside Matlab's bundle, or swap/shadow the bundled ones with other versions with other/more capabilities, as one soon gets drowned in dependency "hell".

Philip Nienhuis <philipnienhuis>
Group Member
Fri 26 Feb 2021 04:44:29 PM UTC, comment #7: 

The methods() function underwent a lot of work to make it more Matlab-compatible.  I remember there were comparisons of the output of Matlab and Octave to determine whether constructors should be listed, etc.  There are probably still differences.

Rik <rik5>
Group administrator
Fri 26 Feb 2021 03:17:07 PM UTC, comment #6: 

I compiled Octave 5.2.0 and tried `methods('java.lang.Double','-full')`. That wasn't supported in that version. So I used the following:

>> methods('java.lang.Double')
Methods for class java.lang.Double:
boolean equals(java.lang.Object)
java.lang.String toString(double)
java.lang.String toString()
int hashCode()
int hashCode(double)
double min(double, double)
double max(double, double)
long doubleToRawLongBits(double)
long doubleToLongBits(double)
double longBitsToDouble(long)
int compareTo(java.lang.Object)
int compareTo(java.lang.Double)
byte byteValue()
short shortValue()
int intValue()
long longValue()
float floatValue()
double doubleValue()
java.lang.Double valueOf(java.lang.String) throws java.lang.NumberFormatException
java.lang.Double valueOf(double)
java.lang.String toHexString(double)
int compare(double, double)
boolean isNaN(double)
boolean isNaN()
boolean isInfinite(double)
boolean isInfinite()
boolean isFinite(double)
double sum(double, double)
double parseDouble(java.lang.String) throws java.lang.NumberFormatException
void wait(long) throws java.lang.InterruptedException
void wait(long, int) throws java.lang.InterruptedException
void wait() throws java.lang.InterruptedException
java.lang.Class getClass()
void notify()
void notifyAll()


In Octave 7.0.0 (hg id ca1cc1bca9cb):

Methods for class java.lang.Double:
Double(double)
Double(java.lang.String) throws java.lang.NumberFormatException
boolean equals(java.lang.Object)
java.lang.String toString(double)
java.lang.String toString()
int hashCode()
int hashCode(double)
double min(double, double)
double max(double, double)
long doubleToRawLongBits(double)
long doubleToLongBits(double)
double longBitsToDouble(long)
int compareTo(java.lang.Object)
int compareTo(java.lang.Double)
byte byteValue()
short shortValue()
int intValue()
long longValue()
float floatValue()
double doubleValue()
java.lang.Double valueOf(java.lang.String) throws java.lang.NumberFormatException
java.lang.Double valueOf(double)
java.lang.String toHexString(double)
int compare(double, double)
boolean isNaN(double)
boolean isNaN()
boolean isInfinite(double)
boolean isInfinite()
boolean isFinite(double)
double sum(double, double)
double parseDouble(java.lang.String) throws java.lang.NumberFormatException
void wait(long) throws java.lang.InterruptedException
void wait(long, int) throws java.lang.InterruptedException
void wait() throws java.lang.InterruptedException
java.lang.Class getClass()
void notify()
void notifyAll()


That looks very similar to me (apart from the constructors now being included -- like you already wrote). Should that be including modifiers (static, ...)?
Maybe that depends on the used Java version?

>> version -java
ans = Java 11.0.10+9-Ubuntu-0ubuntu1.20.10 with Ubuntu OpenJDK 64-Bit Server VM mixed mode, sharing


Please, propose better wording for the documentation if you think it is currently incomplete.

Markus Mützel <mmuetzel>
Group administrator
Fri 26 Feb 2021 12:34:00 PM UTC, comment #5: 

good again is 6.2.0.

I feel also, there are no java developers around...
well I seem the be the only one who uses the interface.
On the other hand, it is a vital aspect of matlab
and shall thus be properly supported.

I would like to help somehow, because I am a java developer...
Well, i am very weak in c/c++ in turn.
We shall cooperate. :))

Ernst Reissner <ernstreissner>
Fri 26 Feb 2021 11:35:36 AM UTC, comment #4: 

In which Octave release was the behavior "good" and in which one "bad" (esp. w.r.t. comment #2)?

I don't think any changes to the Java code were done to cripple the code on purpose; if any it may rather have been unintended side effects of changes elsewhere in the code (e.g., in the interpreter etc.).

In addition we have no real Java developers - that is, not ones with enough time on their hands to fix or improve things.
I'm very sorry for that; I know you've uploaded lots of patches and good ideas for improving the Java subsystem. Unfortunately there's no one around here to pick it up.

Philip Nienhuis <philipnienhuis>
Group Member
Fri 26 Feb 2021 10:30:04 AM UTC, comment #3: 

By the way,
this is not just documentation,
it is matlab compatibility.

https://uk.mathworks.com/help/matlab/ref/methods.html

I think, there are so many things to improve,
why do the developers of octave have time to destroy good code?

Ernst Reissner <ernstreissner>
Fri 26 Feb 2021 10:13:20 AM UTC, comment #2: 

also improved: in intermediate versions methods(.)
behaved almost like methods(.,'-full').
This also changed and it is positive.

What is negative:
behavior of  methods(.,'-full') for java object:
Older version had modifiers static, native and final (at least)
and indication of inheritance of a method.
That way one could see which of the methods
were really defined in the class.

I have the impression, the guy who changed back has no clue on java programming and just removed he did not understand.

I would like to have back old interface
and adaption of documentation.

Ernst Reissner <ernstreissner>
Fri 26 Feb 2021 09:36:31 AM UTC, comment #1: 

You know, I notify you only because my internal tests are broken because of that change. I think the change is positive.

Ernst Reissner <ernstreissner>
Fri 26 Feb 2021 09:35:45 AM UTC, original submission:  

In octave 5.2.0, methods('java.lang.Double')
did not include the constructor, now in 6.2.0 it does.
I think, this shall be added to the documentation,
both manual and help.

The function ismethod was changed accordingly,
and here again, documentation needs clarification.

Also, and I dont know how long this is,
to a complete signature belong
also so called checked exceptions.
These are also given.
Also that shall be noted in the documentation.
Good illustration is really class java.lang.Double.


Ernst Reissner <ernstreissner>

 

(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 jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by ernstreissner (Submitted the item)
  • -email is unavailable- added by ernstreissner
  •  

    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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-26 ernstreissner Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code