Message9943

Author jmadden
Recipients jmadden, stefan.richthofer, zyasoft
Date 2015-04-23.23:11:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429830669.66.0.170731135536.issue2336@psf.upfronthosting.co.za>
In-reply-to
Content
I don't think this is reliably reproducible in an "organic" situation, because it depends on the behaviour of the Java garbage collector, with a reference getting cleared at just the wrong time.

However, I can reliably demonstrate the problem in this reduced example:

  >>> import gc
  >>> from java.lang import Class
  >>> WeakReferenceGC = Class.forName('org.python.modules.gc$WeakReferenceGC')
  # We have to actually construct the right type, the constructor is protected
  # and Jython doesn't expose that to us; we'd get a plain WeakReference
  # if we tried WeakReferenceGC()
  >>> con = WeakReferenceGC.getDeclaredConstructors()[0]
  >>> con.setAccessible(True)
  >>> x = object()
  >>> ref = con.newInstance(x)
  # It works to start with
  >>> ref == ref
  True
  >>> ref.get() is x
  True
  # Now clean up the referent
  >>> del x
  >>> while ref.get():
  ...     _ = gc.collect()
  >>> ref.get()
  # Boom!
  >>> ref == ref
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  java.lang.NullPointerException
	at org.python.modules.gc$WeakReferenceGC.equals(gc.java:709)
        ... 

  java.lang.NullPointerException: java.lang.NullPointerException
History
Date User Action Args
2015-04-23 23:11:09jmaddensetmessageid: <1429830669.66.0.170731135536.issue2336@psf.upfronthosting.co.za>
2015-04-23 23:11:09jmaddensetrecipients: + jmadden, zyasoft, stefan.richthofer
2015-04-23 23:11:09jmaddenlinkissue2336 messages
2015-04-23 23:11:09jmaddencreate