bugGNU Octave - Bugs: bug #39073, java_get wrong return type

 
 

bug #39073: java_get wrong return type

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Sun 26 May 2013 10:38:17 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Ernst Reissner Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 04 May 2015 09:45:01 PM UTC, comment #5: 

Closing report.  This can be re-opened if is found that the solution for bug #44882 does not solve the problem.

Rik <rik5>
Group administrator
Tue 21 Apr 2015 02:30:45 PM UTC, comment #4: 

I have been making some fix for another bug that may affect (see bug ##44882). Where can I get eu.simuline.arithmetics ? How can I test this?

Carnë Draug <carandraug>
Group Member
Sun 26 May 2013 10:54:01 PM UTC, comment #3: 

yes

www.mathworks.de/de/help/matlab/matlab_external/handling-data-returned-from-a-java-method.html#bqgs4dc

seems really valuable.

I cite:
<cite>
Java Objects

When a method call returns Java objects, MATLAB leaves them in their original form. They remain as Java objects so you can continue to use them to interact with other Java methods.

The only exception to this is when the method returns data of type java.lang.Object.
</cite>

So this means that auto(un)boxing of RETURN VALUES
is not conform with matlab.
Of course, object means really a subclass of java.lang.Object.

Not to mix up with using the method double

<cite>
Converting to the MATLAB double Type

Using the double function in MATLAB, you can convert any Java object or array of objects to the MATLAB double type. The action taken by the double function depends on the class of the object you specify:

If the object is an instance of a numeric class (java.lang.Number or one of the classes that inherit from that class), MATLAB uses a preset conversion algorithm to convert the object to a MATLAB double.

If the object is not an instance of a numeric class, MATLAB checks the class definition to see if it implements a method called toDouble. MATLAB uses toDouble to perform its conversion of Java objects to the MATLAB double type. If such a method is implemented for this class, MATLAB executes it to perform the conversion.
.....
</cite>

In by case i have the problem with a class extending java.lang.Number.
I have the impression that the method double is invoked
to convert, which is not allowed.
By the way, i do not define method toDouble.



Ernst Reissner <ernstreissner>
Sun 26 May 2013 09:57:20 PM UTC, comment #2: 


Yes ist is obviously a problem with auto(un)boxing.
How it should work to be ML-compatible is described in


http://www.mathworks.de/de/help/matlab/matlab_external/handling-data-returned-from-a-java-method.html#bqgs4dc


I have the impression, that the problem returning a double although i have an object other than of class java.lang.Object
occurs in case the according class has a method doubleValue(), like java.lang.Number.
In fact the problem not being able to display the proper class
seems to have to do that i extend java.lang.Number.
Or maybe that i implement ernst.reissner.Number, i.e. my own number, which has the same short name as the one from java.lang.

I think something is implemented relying on a half truth.
But maybe not so difficult to fix.



Ernst Reissner <ernstreissner>
Sun 26 May 2013 08:28:28 PM UTC, comment #1: 

That probably happens because of auto-boxing and -unboxing.

There were a few threads on it in the maintainers list. See e.g., here:
https://mailman.cae.wisc.edu/pipermail/octave-maintainers/2012-December/031440.html
--and especially--
https://mailman.cae.wisc.edu/pipermail/octave-maintainers/2013-January/031844.html

Background:
That it worked in the OF Java package and not in current core dev Octave is because the boxing/unboxing scheme has been made "Matlab compatible".
Initially I also frowned on this (believe me) but up till now all delicate Java calls in the io package (of which I'm the maintainer), especially to UNO (LibreOffice etc), could be gotten to work properly with that new ML-compatible scheme. In the end, that is :-) - after all 3.7.x is a development version where things can break any moment.
FYI that you sometimes only get "Java Object> rather than <Java Object: <Java Class>> doesn't imply 1:1 that Java can't cope with it.

I interpret all of this as "Only if your specific Java method doesn't work with doubles handed to it from Octave this bug would be valid."
You mention that you cannot get your Java method to work, so the above seems valid. Can you invoke the Java method in question with javaMethod? (I wonder if it would make any difference)

Do you have a simple test case the devs can try (and debug?)
Do you also have access to the Java source code for your methods to see what class it expects exactly?

(Category set to "Libraries")

Philip Nienhuis <philipnienhuis>
Group Member
Sun 26 May 2013 10:38:17 AM UTC, original submission:  


i use octave 3.7.5 to check for sth.

examples:

x=java_get("eu.simuline.arithmetics.MathExt", "CONTEXT_DUAL_DOUBLE")
x =

<Java object: java.math.MathContext>

is ok.


 x=java_get("eu.simuline.arithmetics.left2right.XFPNumberMult","X_MATH_CONTEXT")
x =

<Java object: >


is not entirely ok but does not matter (classname missing)


x=java_get("eu.simuline.arithmetics.left2right.XFPNumberMult","ONE")
x =  1


very bad because class(x) is double
although it should be <Java object: XXX>

The bad effect is that i cannot access a method of x
via x.method() notation.

I know that this was different in Michael Gouffiols old package.



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 rik5 (Posted a comment)
  • -email is unavailable- added by ernstreissner (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-05-04 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2013-05-26 philipnienhuis CategoryOctave Function Libraries

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code