Author stefan.richthofer
Recipients stefan.richthofer
Date 2017-02-08.14:21:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
ERROR: test_sort (__main__.JavaListTestCase)
Traceback (most recent call last):
  File "/data/workspace/linux/Jython/ssh/jython/dist/Lib/test/", line 442, in test_sort
  File "/data/workspace/linux/Jython/ssh/jython/dist/Lib/test/", line 446, in _test_sort
TypeError: sort(): expected 1 args; got 0


I investigated a bit and found that the object in question is of type ArrayList and indeed:

Jython 2.7.1b3 (, Feb 8 2017, 02:12:28) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import ArrayList
>>> lst = ArrayList([1, 0])
>>> lst.sort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sort(): expected 1 args; got 0

In Java 7 this passes without complain.
So what shall this arg be that is suddenly required in Java 8? Let's try:

>>> lst.sort(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sort(): 1st arg can't be coerced to java.util.Comparator

So, looking into Java 8 ArrayList, etc: Lists have a sort method now and Jython seems to prefer that over the original Jython-style sort method. The Java sort-method however requires a comparator, which can be null to fallback to some default behavior (what is probably what we want).

To fix this in a Java version independent fashion I'd suggest to blacklist methods called 'sort' for JavaTypes that implement java.util.List, when going through methods in PyJavaType.init. This should assure that Jython always chooses the right sort-method.

Maybe we can alternatively implement an overloading logic for these methods. I'd suggest to add this as an enhancement to this solution later on.
Date User Action Args
2017-02-08 14:21:17stefan.richthofersetrecipients: + stefan.richthofer
2017-02-08 14:21:17stefan.richthofersetmessageid: <>
2017-02-08 14:21:17stefan.richthoferlinkissue2550 messages
2017-02-08 14:21:15stefan.richthofercreate