From: <pj...@us...> - 2009-12-03 03:22:33
|
Revision: 6954 http://jython.svn.sourceforge.net/jython/?rev=6954&view=rev Author: pjenvey Date: 2009-12-03 03:22:11 +0000 (Thu, 03 Dec 2009) Log Message: ----------- fix ConcurrentHashSet serialization: Object isn't serializable fixes #1511 Modified Paths: -------------- trunk/jython/Lib/test/test_set_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/util/ConcurrentHashSet.java Modified: trunk/jython/Lib/test/test_set_jy.py =================================================================== --- trunk/jython/Lib/test/test_set_jy.py 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/Lib/test/test_set_jy.py 2009-12-03 03:22:11 UTC (rev 6954) @@ -2,6 +2,8 @@ from test import test_support if test_support.is_jython: + from java.io import (ByteArrayInputStream, ByteArrayOutputStream, + ObjectInputStream, ObjectOutputStream) from java.util import Random from javatests import PySetInJavaTest @@ -48,7 +50,18 @@ # Check that the Java removal affected the underlying set self.assertEquals(0, len(s)) + def test_serialization(self): + s = set(range(5, 10)) + output = ByteArrayOutputStream() + serializer = ObjectOutputStream(output) + serializer.writeObject(s) + serializer.close() + input = ByteArrayInputStream(output.toByteArray()) + unserializer = ObjectInputStream(input) + self.assertEqual(s, unserializer.readObject()) + + def test_main(): tests = [SetTestCase] if test_support.is_jython: Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/NEWS 2009-12-03 03:22:11 UTC (rev 6954) @@ -12,6 +12,7 @@ - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError - [ 1396 ] Assigning os module funcs as class attributes incompatible with CPython - [ 1504 ] Inheriting twice from the same Java interface causes MRO problems + - [ 1511 ] PySet doesn't support Java serialization - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/core/util/ConcurrentHashSet.java =================================================================== --- trunk/jython/src/org/python/core/util/ConcurrentHashSet.java 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/src/org/python/core/util/ConcurrentHashSet.java 2009-12-03 03:22:11 UTC (rev 6954) @@ -17,26 +17,23 @@ public class ConcurrentHashSet<E> extends AbstractSet<E> implements Serializable { /** The backing Map. */ - private final ConcurrentMap<E, Object> map; + private final ConcurrentMap<E, Boolean> map; /** Backing's KeySet. */ private transient Set<E> keySet; - /** Dummy value to associate with the key in the backing map. */ - private static final Object PRESENT = new Object(); - public ConcurrentHashSet() { - map = new ConcurrentHashMap<E, Object>(); + map = new ConcurrentHashMap<E, Boolean>(); keySet = map.keySet(); } public ConcurrentHashSet(int initialCapacity) { - map = new ConcurrentHashMap<E, Object>(initialCapacity); + map = new ConcurrentHashMap<E, Boolean>(initialCapacity); keySet = map.keySet(); } public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) { - map = new ConcurrentHashMap<E, Object>(initialCapacity, loadFactor, concurrencyLevel); + map = new ConcurrentHashMap<E, Boolean>(initialCapacity, loadFactor, concurrencyLevel); keySet = map.keySet(); } @@ -72,7 +69,7 @@ @Override public boolean add(E e) { - return map.put(e, PRESENT) == null; + return map.put(e, Boolean.TRUE) == null; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |