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

 
 

bug #39073: java_get wrong return type

Submitted by:  Ernst Reissner <ernstreissner>
Submitted on:  Sun 26 May 2013 10:38:17 AM UTC  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Ernst ReissnerOpen/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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>
Project Member
Sun 26 May 2013 10:54:01 PM UTC, comment #3:

yes
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

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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by ernstreissner (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 04 May 2015 09:45:01 PM UTCrik5StatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Sun 26 May 2013 08:28:28 PM UTCphilipnienhuisCategoryOctave Function=>Libraries

    Back to the top


    Powered by Savane 3.1-cleanup1