Overloaded Java method handing changes between 2.7.2 and 2.7.3?
John Hubbard <[email protected]> Thu, 6 Jun 2024 15:38:07 -0600
| Newsgroups | gmane.comp.lang.jython.user |
|---|---|
| Message-ID | <CAO2imXwGeO1Gh+1i1zT0gAWX0mzoMNzvHWp=WqeGXZUp70U=jQ@mail.gmail.com> |
--===============7755225296443781805==
Content-Type: multipart/alternative; boundary="000000000000cbaaf6061a3f8103"
--000000000000cbaaf6061a3f8103
Content-Type: text/plain; charset="UTF-8"
Hello,
Has something changed between Jython 2.7.2 and Jython 2.7.2 with regards to
how calls from Jython to an overloaded Java method are resolved?
*Background*
I am trying to update our application from Jython 2.7.2 to Jython 2.7.3 and
I have run into what I think is a change in how Jython handles overloaded
Java methods. The primary motivation for the update is proper handling of
* imports under JDK 17 (and JUnit 5); see Jython GitHub issues 105, 304 and
maybe 309.
Our application is primarily Java based but uses Jython for high level
scripts which perform high level sequencing. One of the most common things
those scripts do is construct 'bags of data' which are handled by our
AttributeTable class (full jdoc here
<https://share.nso.edu/shared/dkist/jhubbard/atst/atst/cs/interfaces/IAttributeTable.html>).
That class is backed by a Map<String, String[]> and stores heterogenous
data via various via getters and setters like:
insert(String name, String value)
insert(String name, int value)
insert(String name, boolean value)
...
String getString(String name)
int getInt(String name)
With Jython 2.7.2 I could could write a script like:
tbl = AttributeTable();
name = 'name'
value = 27
tbl.insert(name, value)
and it would behave as expected. Jython would resolve the insert call to
the Java AttributeTable.insert(String, int) method, the Java side would
then convert the integer 27 into the String "27" and store it in the map
for later use.
*Problem*
With Jython 2.7.3 I think that the truthiness of the value is being
evaluated and AttributeTable.insert(String, boolean) is what is getting
triggered. For example the following code:
def savePropertyValue(appName, propertyName, propertyValue):
print('savePropertyValue(' + str(appName) + ', ' + str(propertyName)
+ ', ' + str(propertyValue) + ')')
at = AttributeTable()
at.insert(propertyName, propertyValue)
at.show('savePropertyValue() AttributeTable ')
produces
savePropertyValue(atst.ics.visp, atst.ics.visp.slitStepSz, 0.05)
savePropertyValue() AttributeTable atst.ics.visp.slitStepSz: true
So the value 0.05 was passed into the jython savePropertyValue function but
what ended up being inserted into the Java AttributeTable object was the
boolean true.
*Questions*
1. What is the expected behavior when interacting with overloaded Java
objects? Were we just lucky before and this was never expected to work?
2. Is anyone aware of changes on the Java side that may have triggered
this? I'd like some background on what might have caused this so I can
investigate what might be improved to fix this.
3. Is it possible to inject custom PyObject --> Java Object coercion
routines? The interpreters are setup at a high level; if I could mask the
Java AttributeTable class with a Python class that better handled
overloaded methods and then somehow coerce/convert it to an Java
AttributeTable before sending it back into Java land I might be able to
work around this.
Thanks
--
Cheers
-john
--000000000000cbaaf6061a3f8103
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr">Hello,=C2=A0</div><div dir=3D"ltr"><br></=
div><div dir=3D"ltr">Has something changed between Jython 2.7.2 and Jython =
2.7.2 with regards to how calls from Jython to an overloaded Java method ar=
e resolved?=C2=A0=C2=A0<br><div><br></div><div><b>Background</b><br></div><=
div>I am trying to update our application from Jython 2.7.2 to Jython 2.7.3=
and I have run into what I think is a change in how Jython handles overloa=
ded Java methods.=C2=A0 The primary motivation for the update is proper han=
dling of * imports under JDK 17 (and JUnit 5); see Jython GitHub issues 105=
, 304 and maybe 309.=C2=A0=C2=A0</div><div><br></div><div>Our application i=
s primarily Java based but uses Jython for high level scripts which perform=
high level sequencing.=C2=A0 One of the most common things those scripts d=
o is construct 'bags of data' which are handled by our AttributeTab=
le class (full jdoc <a href=3D"https://share.nso.edu/shared/dkist/jhubbard/=
atst/atst/cs/interfaces/IAttributeTable.html" target=3D"_blank">here</a>).=
=C2=A0 That class is backed by a Map<String, String[]> and stores het=
erogenous data via various via getters and setters like:</div><blockquote s=
tyle=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face=3D=
"monospace">insert(String name, String value)</font></div><div><font face=
=3D"monospace">insert(String name, int value)</font></div></blockquote><blo=
ckquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><fon=
t face=3D"monospace">insert(String name, boolean value)</font></div></block=
quote><blockquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"=
><div><font face=3D"monospace">...</font></div></blockquote><blockquote sty=
le=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face=3D"m=
onospace">String getString(String name)</font></div></blockquote><blockquot=
e style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face=
=3D"monospace">int getInt(String name)</font></div></blockquote><div><br></=
div><div>With Jython 2.7.2 I could could write a script like:</div><blockqu=
ote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><font fa=
ce=3D"monospace">tbl =3D AttributeTable();</font></div><div><font face=3D"m=
onospace">name =3D 'name'</font></div><div><font face=3D"monospace"=
>value =3D 27</font></div><div><font face=3D"monospace">tbl.insert(name, va=
lue)</font></div></blockquote><div>and it would behave as expected.=C2=A0 J=
ython would resolve the insert call to=C2=A0 the Java AttributeTable.insert=
(String, int) method, the Java side would then convert the integer 27 into =
the String "27" and store it in the map for later use.=C2=A0=C2=
=A0</div><div><br></div><div><b>Problem</b></div><div>With Jython 2.7.3 I t=
hink that the truthiness of the value is being evaluated and AttributeTable=
.insert(String, boolean)=C2=A0is what is getting triggered.=C2=A0 For examp=
le the following code:</div></div><blockquote style=3D"margin:0 0 0 40px;bo=
rder:none;padding:0px"><div><div><div><font face=3D"monospace">def saveProp=
ertyValue(appName, propertyName, propertyValue):</font></div></div></div><d=
iv><div><div><font face=3D"monospace">=C2=A0 print('savePropertyValue(&=
#39; + str(appName) + ', ' + str(propertyName)</font></div></div></=
div><div><div><div><font face=3D"monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 + ', ' + str(propertyValue) + ')')</font></div></div></=
div><div><div><div><font face=3D"monospace">=C2=A0 at =3D AttributeTable()<=
/font></div></div></div><div><div><div><font face=3D"monospace">=C2=A0 at.i=
nsert(propertyName, propertyValue)</font></div></div></div><div><div><div><=
font face=3D"monospace">=C2=A0 at.show('savePropertyValue() AttributeTa=
ble ')</font></div></div></div></blockquote><div dir=3D"ltr"><div>produ=
ces=C2=A0</div></div><blockquote style=3D"margin:0 0 0 40px;border:none;pad=
ding:0px"><div dir=3D"ltr"><div><font face=3D"monospace">savePropertyValue(=
atst.ics.visp, atst.ics.visp.slitStepSz, 0.05)<br>savePropertyValue() Attri=
buteTable atst.ics.visp.slitStepSz: true</font><br></div></div></blockquote=
><div dir=3D"ltr"><div><br></div><div>So the value 0.05 was passed into the=
jython savePropertyValue function but what ended up being inserted into th=
e Java AttributeTable object was the boolean true.=C2=A0=C2=A0</div><div><b=
r></div><div><b>Questions</b></div><div><ol><li>What is the expected behavi=
or when interacting with overloaded Java objects?=C2=A0 Were we just lucky =
before and this was never expected to work?</li><li>Is anyone aware of chan=
ges on the Java side that may have triggered this?=C2=A0 I'd like some =
background on what might have caused this so I can investigate what might b=
e improved to fix this.</li><li>Is it possible to inject custom PyObject --=
> Java Object coercion routines?=C2=A0 The interpreters are setup at a h=
igh level; if I could mask the Java AttributeTable class with a Python clas=
s that better handled overloaded methods and then somehow coerce/convert it=
to an Java AttributeTable before sending it back into Java land I might be=
able to work around this.</li></ol><div>Thanks</div></div><div><br></div><=
div><div><div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr">--<div=
>Cheers</div><div>-john</div></div></div></div></div></div></div>
--000000000000cbaaf6061a3f8103--
--===============7755225296443781805==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============7755225296443781805==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users
--===============7755225296443781805==--