Title: regression in PyReflectedFunction: static Java methods are no longer callable
Type: behaviour Severity: urgent
Components: Core Versions: Jython 2.5
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: doublep, fwierzbicki, jeff.allen, stefan.richthofer, zyasoft
Priority: low Keywords:

Created on 2011-04-26.14:29:31 by doublep, last changed 2018-07-02.13:34:36 by doublep.

File name Uploaded Description Edit Remove doublep, 2011-04-26.14:33:30 testcase
msg6516 (view) Author: (doublep) Date: 2011-04-26.14:29:30
This is a regression in 2.5.2 compared to 2.5.1.  In 2.5.1 the attached script produces no output as it should.  In 2.5.2 it fails with java.lang.NegativeArraySizeException.

In a real code I also see 'some_function(): expected 1 args; got 0' when executing 'some_function ('bla')' --- this also worked fine in 2.5.1.
msg6517 (view) Author: (doublep) Date: 2011-04-26.14:33:30
Please disregard '' --- it is a wrong file.  See this short Java code instead.
msg6556 (view) Author: (doublep) Date: 2011-06-20.15:28:36
msg9047 (view) Author: Jim Baker (zyasoft) Date: 2014-09-26.05:58:40
Interesting usage of Jython's internals
msg9051 (view) Author: (doublep) Date: 2014-09-26.07:10:35
Well, how do I tell apart internals from not? PyNone is in the same package, for instance.

PyReflectedFunction seems to be a good way to make Java methods available to scripts detached from their classes. What I do is collect a number of "very common" methods from my application and make them visible to scripts without importing anything, much like builtins.
msg11823 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-17.13:41:46
Is there a thing to fix here, or just to be clearer what is meant to be public?
msg11996 (view) Author: (doublep) Date: 2018-05-18.10:44:51
Ideally I would of course prefer that original semantics is restored. It was a simple way to make static functions (i.e. something not attached to a "bean") to Jython scripts.

In our application Jython is used for lots of simple scripts (5-30 lines). I prefer to make certain common functions available to them without requiring an explicit imports, i.e. similar to builtins.
msg12016 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-06-24.13:05:21
Did you try to use Py.newJavaFunc instead of PyReflectedFunction?
msg12021 (view) Author: (doublep) Date: 2018-06-27.16:35:30
How would I even use it? It expects a method in my class that accepts PyObject[] and String[]... Presumably, those are arguments and their names. However, what I'm doing with old PyReflectedFunction (yes, because of this bug I never upgraded to newer Jython) is wrapping arbitrary Java methods with arbitrary argument types. Additionally, PyReflectedFunction can resolve overrides with different number of arguments for me.
msg12030 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-06-27.23:17:21
(I don't want to argue about this being an issue that needs a fix. Just wanted to suggest a workaround until a fix is available.)
You're right, Py.newJavaFunc requires your function to have a special signature. Regarding the notation in your file, what about the following workaround:

python.exec ("test = System.gc");
python.exec ("test ()");

Did you try that?
msg12041 (view) Author: (doublep) Date: 2018-07-02.13:34:35
No, I didn't try that, but it does look like it'd give the result I need.
Date User Action Args
2018-07-02 13:34:36doublepsetmessages: + msg12041
2018-06-27 23:17:21stefan.richthofersetmessages: + msg12030
2018-06-27 16:35:30doublepsetmessages: + msg12021
2018-06-24 13:05:21stefan.richthofersetnosy: + stefan.richthofer
messages: + msg12016
2018-05-18 10:44:51doublepsetmessages: + msg11996
2018-03-17 13:41:46jeff.allensetnosy: + jeff.allen
messages: + msg11823
2018-03-17 13:36:13jeff.allensetfiles: -
2014-09-26 07:10:35doublepsetmessages: + msg9051
2014-09-26 05:58:40zyasoftsetpriority: normal -> low
assignee: fwierzbicki ->
messages: + msg9047
nosy: + zyasoft
2013-02-19 23:55:06fwierzbickisetpriority: normal
assignee: fwierzbicki
resolution: remind
nosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.2rc
2011-06-20 15:28:36doublepsetmessages: + msg6556
2011-04-26 14:33:30doublepsetfiles: +
messages: + msg6517
2011-04-26 14:29:31doublepcreate