bugGNU Octave - Bugs: bug #55487, ismethod of custom classdefs...

 
 

bug #55487: ismethod of custom classdefs always returning false

Submitter:  Markus Ebner <seijikun>
Submitted:  Wed 16 Jan 2019 10:01:17 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 22 Feb 2019 01:48:21 AM UTC, comment #11: 

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Thu 21 Feb 2019 06:58:31 PM UTC, comment #10: 

The problem with Java methods should be fixed with the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/8554becefe1b

I also added some tests for ismethod:

http://hg.savannah.gnu.org/hgweb/octave/rev/c4e53014f248

Is there anything else that needs to be done here?

John W. Eaton <jwe>
Group administrator
Thu 21 Feb 2019 05:03:56 PM UTC, comment #9: 

See bug #48742 for Java 'methods(obj)' and 'methods(obj, "-full")'.

Mike Miller <mtmiller>
Group Member
Mon 18 Feb 2019 10:20:52 PM UTC, comment #8: 

Yes, seems like it would be a good idea to implement '-full' for methods().  Also, I notice that Matlab returns a column vector rather than a row vector of function names.  Maybe that doesn't matter so much, but it would be easy to change.  Finally, methods() on java.lang.String returns 91 methods in Matlab and only 76 in Octave.  In Matlab, first all constructors are returned.  After that, methods are returned in alphabetical order.  In Octave, the methods are returned in some higgledy-piggledy order.

Rik <rik5>
Group administrator
Mon 18 Feb 2019 08:29:36 PM UTC, comment #7: 

Oops, comment #5 should have been

Hmm, if you do


methods ('java.lang.String')


you'll see that the list of methods includes type information.  So the simple ismember check on the result returned by methods doesn't work to match
'hashCode'.

Also, the Matlab docs say that methods with the '-full' option will return type signature info for Java and Matlab methods.

So I guess we should strip the type info from the output of methods unless the option '-full' is supplied?

John W. Eaton <jwe>
Group administrator
Mon 18 Feb 2019 08:05:18 PM UTC, comment #6: 

Looks like the comment was cut off because the verbatim tag was misspelled.

In any case, I tried in Matlab and methods() returns only the function name.  It does not return the output type, nor does it include the extra parentheses '()'.

Either we change how methods() returns data from Java objects, or if we like the extra verbosity about the function, then we have to change ismethod to possibly use a regular expression to remove extraneous information.

This regexp would work


mtd = regexprep (methods (x), '^(?:[^ ]+ )+(\w+)\(.*$', '$1')


Of course, this leaves duplicates in the list of methods.  But that doesn't really matter because you could then use


retval = any (strcmp (method, method_list));


rather than


retval = ismember (method, method_list);


This will probably be faster because ismember is rather slow.


Rik <rik5>
Group administrator
Mon 18 Feb 2019 07:34:14 PM UTC, comment #5: 

Hmm, if you do


methods ('java.lang.String')
-vertabim-

you'll see that the list of methods includes type information.  So the simple ismember check on the result returned by methods doesn't work to match 'hashCode'.

John W. Eaton <jwe>
Group administrator
Mon 18 Feb 2019 07:20:08 PM UTC, comment #4: 

In answer to comment #2, yes, Matlab allows ismethod on Java objects.  The following returns true in Matlab:


x = javaObject ('java.lang.String', 'Hello World')
ismethod (x, 'hashCode')


Octave still returns false for the example code above.

On the positive side, ismethod in Octave now works correctly for classdef objects and for the original code in this report.

Rik <rik5>
Group administrator
Mon 18 Feb 2019 05:06:58 PM UTC, comment #3: 
John W. Eaton <jwe>
Group administrator
Mon 18 Feb 2019 04:52:03 PM UTC, comment #2: 

In Matlab, does ismethod also work for Java objects?

John W. Eaton <jwe>
Group administrator
Sun 17 Feb 2019 10:54:49 PM UTC, comment #1: 

Confirmed.  Adding jwe to the CC list since he has just been working on the methods() function for classes.

With the test code in this bug report, calling methods ('testclass') returns the class method "getNumber".  So, to some extent, Octave knows about the method.  But ismethod returns false.

Rik <rik5>
Group administrator
Wed 16 Jan 2019 10:01:17 AM UTC, original submission:  

Having the following classdef in file testclass.m:


classdef testclass
        properties
                testnumber = 0;
        endproperties

        methods
                function p = testclass()
                        p.testnumber = 1337;
                endfunction

                function result = getNumber(obj)
                        result = obj.testnumber;
                endfunction
        endmethods
endclassdef


The ismethod() function (if I understood it correctly from the matlab documentation) should return true, if the class or object given as first parameter has a public method with the name given as second parameter. So the following calls to ismethod should return true:


testinstance = testclass();
ismethod(testinstance, 'getNumber')
ismethod('testclass', 'getNumber')


But they return false.

Markus Ebner <seijikun>

 

(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 rik5
  • -email is unavailable- added by seijikun (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-22 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2019-02-18 jwe StatusNone Ready For Test
    2019-02-17 rik5 Release4.4.1 dev
        Carbon-Copy- Added jwe

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code