Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] problem accessing java math class constants #5090

Open
jh-midi opened this issue Oct 16, 2023 · 8 comments
Open

[BUG] problem accessing java math class constants #5090

jh-midi opened this issue Oct 16, 2023 · 8 comments
Milestone

Comments

@jh-midi
Copy link

jh-midi commented Oct 16, 2023

declare namespace math="java:java.lang.Math";

math:sqrt(2) (: work well :)

(: but access of class constant don't work as expected :)

declare namespace math="java:java.lang.Math";
math:PI() (: don't work :)

SAXON example

<a xmlns:double="java:java.lang.Double"> 
    { double:MAX_VALUE() } don't work
</a>

existdb 6.2.0

@adamretter
Copy link
Member

This is disabled in eXist-db by default. You would need to change enable-java-binding="no" to enable-java-binding="yes" in your eXist-db's conf.xml file.

@jh-midi
Copy link
Author

jh-midi commented Oct 16, 2023

yes, this is enabled : and function work

declare namespace double = "java:java.lang.Double";

double:doubleValue(xs:integer(50)) 

=> 5.0e1 => "ok"

but

declare namespace double = "java:java.lang.Double";

double:MAX_VALUE()

=> Cannot compile xquery: exerr:ERROR no method matches MAX_VALUE with 0 arguments [at line 5, column 1, source: String/-3378769710902313501]

the same error occur with

Math:PI()

I am on jdk-17.0.8.7-hotspot Eclipse Adoptium

@joewiz joewiz reopened this Oct 16, 2023
@joewiz joewiz changed the title [BUG] [BUG] problem accessing java math class constants Oct 16, 2023
@joewiz joewiz added the bug issue confirmed as bug label Oct 16, 2023
@joewiz joewiz added this to the eXist-6.2.1 milestone Oct 16, 2023
@jh-midi
Copy link
Author

jh-midi commented Oct 16, 2023

Thank you very much !
NOTICE:
double:doubleValue(xs:integer(50)) is not a very good example because normaly it should not work
because xs:integer is not xs:double ...

declare namespace double = "java:java.lang.Double";
double:doubleValue(xs:double(50)) ,
double:intValue(xs:double(100.55)) ,
double:MAX_VALUE()

expected result = (50, 100, 1.7976931348623157E308)

@adamretter
Copy link
Member

double:MAX_VALUE()

MAX_VALUE is not a function call in Java it is a constant, so try changing your XQuery from double:MAX_VALUE() to $double:MAX_VALUE.

Math:PI()

Likewise, this is not a function in java.lang.Math, it is a constant. Try:

declare namespace math = "java:java.lang.Math";
$math:PI

@joewiz joewiz removed the bug issue confirmed as bug label Oct 16, 2023
@jh-midi
Copy link
Author

jh-midi commented Oct 16, 2023

Have you tried that on eXide ?
Here this don't work .
Sorry,

with Saxon and Basex my script work well

@jh-midi
Copy link
Author

jh-midi commented Oct 16, 2023

eXideMath

@jh-midi
Copy link
Author

jh-midi commented Oct 16, 2023

@adamretter adamretter reopened this Oct 16, 2023
@adamretter
Copy link
Member

adamretter commented Oct 16, 2023

Have you tried that on eXide

No. Apologies, I tried it elsewhere.

Here this don't work .

I can now confirm that eXist-db does not support accessing anything apart from static functions, or functions via a previously invoked constructor.

with Saxon and Basex my script work well

You or someone else would need to send a PR to add a feature to eXist-db to support Java class members (e.g. constants) and/or public non-static members. The relevant class in eXist-db is currently org.exist.xquery.JavaCall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants