From: John H. <jhu...@ns...> - 2024-06-06 23:19:12
|
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 |