Issue1781

classification
Title: Jython selects wrong overload when Boolean/boolean choices are involved
Type: Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution: later
Dependencies: Superseder:
Assigned To: Nosy List: doublep, fwierzbicki, zyasoft
Priority: low Keywords:

Created on 2011-07-25.15:50:12 by doublep, last changed 2015-02-23.11:05:05 by doublep.

Files
File name Uploaded Description Edit Remove
test.java doublep, 2011-07-25.15:50:11 standalone example demonstrating the bug
Messages
msg6584 (view) Author: (doublep) Date: 2011-07-25.15:50:11
This is a real-world failure with JFreeCharts.  Attached testcase is just what I saw there distilled to 20 lines, without dependencies.
msg7738 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-25.18:35:29
Thanks for the detailed report, sorry this has stagnated. I'll try to get this looked at. Setting to high to try to poke my future self.
msg8693 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.00:55:29
In part this is a historical artifact of how Python, and consequently, Jython, implemented boolean support. Prior to 2.3, there was no boolean type, only int support.

But we have moved on. The relevant logic is in ReflectedArgs; it selects integer first, which is a valid conversion from boolean, if the parameter is primitive (see the precedence method). We should special case this to select boolean first, since this clearly should have precedence.

2.7.0 is a good time to make this change, since it can break code.

Target beta 4
msg9333 (view) Author: Jim Baker (zyasoft) Date: 2015-01-07.07:01:32
Backwards breaking, must fix
msg9350 (view) Author: Jim Baker (zyasoft) Date: 2015-01-07.21:47:42
Delaying indefinitely this idea. The problem is that in general this is an exponential search problem because each choice - int OR boolean - should be optimized at the callsite for the specific invocation.

But there's a much simpler - and standard Jython - workaround for now. Using the example in the attached test.java:

from java.lang import Integer
import test; test.lol (Integer(0), False)

will call the desired overloaded method. This is because there's no longer a choice of attempting to coerce in __tojava__ to a Java boolean or an int.

I don't see us re-exploring this sort of idea before type hinting and Jython 3.x
msg9554 (view) Author: (doublep) Date: 2015-02-23.11:05:05
It might be exponential, but in practice most method don't have more than some 3 parameters.
History
Date User Action Args
2015-02-23 11:05:05doublepsetmessages: + msg9554
2015-01-07 21:47:53zyasoftsetassignee: zyasoft ->
resolution: later
2015-01-07 21:47:42zyasoftsetpriority: urgent -> low
messages: + msg9350
2015-01-07 07:01:32zyasoftsetpriority: high -> urgent
assignee: fwierzbicki -> zyasoft
messages: + msg9333
2014-06-19 00:55:37zyasoftsetversions: + Jython 2.7, - Jython 2.5
2014-06-19 00:55:29zyasoftsetnosy: + zyasoft
messages: + msg8693
2013-02-25 18:35:29fwierzbickisetpriority: high
assignee: fwierzbicki
messages: + msg7738
nosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.1
2011-07-25 15:50:12doublepcreate