Issue2381

classification
Title: Wrong return type of Java map's values() method
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: kaneg, zyasoft
Priority: Keywords:

Created on 2015-07-23.09:31:08 by kaneg, last changed 2015-09-01.20:39:54 by zyasoft.

Messages
msg10163 (view) Author: Kane Gong (kaneg) Date: 2015-07-23.09:31:08
In Jython 2.7, Java's Map instance, e.g. HashMap, its values() method returns a Non-Java type which will cause unexpected behavior. In old Jython 2.5, it is right. Details are in below:

Below is the behavior in Jython 2.7:

Jython 2.7.0+ (, May 18 2015, 14:16:04)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_51
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import HashMap
>>> HashMap().values().iterator()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'iterator'
>>> type(HashMap().values())
<type 'list'>

Below is the behavior in Jython 2.5
Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_51
>>> from java.util import HashMap
>>> m = HashMap()
>>> m.values()
[]
>>> m.values().iterator()
java.util.HashMap$ValueIterator@3d246ea3
>>> type(m.values())
<type 'java.util.HashMap$Values'>
msg10175 (view) Author: Jim Baker (zyasoft) Date: 2015-08-10.23:16:29
This was a backwards breaking change to make objects implementing java.util.Map behave as if they are dict-like, and therefore satisfy the contract of https://docs.python.org/2/library/collections.html#collections.MutableMapping:

$ jython27
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_45
Type "help", "copyright", "credits" or "license" for more information.
>>> import java
>>> m = java.util.HashMap()
>>> from collections import MutableMapping
>>> isinstance(m, MutableMapping)
True

See https://hg.python.org/jython/rev/864bbec6ddb5
History
Date User Action Args
2015-09-01 20:39:54zyasoftsetstatus: pending -> closed
2015-08-10 23:16:30zyasoftsetstatus: open -> pending
resolution: rejected
messages: + msg10175
nosy: + zyasoft
2015-07-23 09:31:08kanegcreate