Issue2696

classification
Title: open(None) results in java.lang.ClassCastException
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jaraco
Priority: Keywords:

Created on 2018-07-06.03:02:40 by jaraco, last changed 2018-07-06.03:05:22 by jaraco.

Messages
msg12043 (view) Author: Jason R. Coombs (jaraco) Date: 2018-07-06.03:02:39
On CPython, invoking open(None) results in a Python Exception (TypeError). On jython, it crashes with a Java exception:

>>> open(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.ClassCastException: org.python.core.PyNone cannot be cast to org.python.core.PyString
        at org.python.core.PyFile.file___init__(PyFile.java:173)
        at org.python.core.PyFile$exposed___new__.createOfType(Unknown Source)
        at org.python.core.PyOverridableNew.new_impl(PyOverridableNew.java:12)
        at org.python.core.PyType.invokeNew(PyType.java:583)
        at org.python.core.PyType.type___call__(PyType.java:1815)
        at org.python.core.PyType.__call__(PyType.java:1805)
        at org.python.core.OpenFunction.__call__(__builtin__.java:1725)
        at org.python.core.PyObject.__call__(PyObject.java:480)
        at org.python.core.PyObject.__call__(PyObject.java:484)
        at org.python.pycode._pyx4.f$0(<stdin>:1)
        at org.python.pycode._pyx4.call_function(<stdin>)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.Py.exec(Py.java:1658)
        at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
        at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:116)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:62)
        at org.python.util.InteractiveConsole.push(InteractiveConsole.java:187)
        at org.python.util.InteractiveConsole._interact(InteractiveConsole.java:168)
        at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:126)
        at org.python.util.jython.run(jython.java:419)
        at org.python.util.jython.main(jython.java:142)
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyNone cannot be cast to org.python.core.PyString


As a result, [code like this](https://github.com/jaraco/rwt/blob/0ef1080da43827787846f32c698fe7286d6a7613/rwt/scripts.py#L50-L54) fails to catch the exception.

Perhaps that's by design and the offending code should simply catch BaseException instead. Probably better would be for Jython to raise the same TypeError.
msg12044 (view) Author: Jason R. Coombs (jaraco) Date: 2018-07-06.03:05:22
I note that catching BaseException also has no effect.

I do observe that using `io.open` has consistent behavior across Pythons.
History
Date User Action Args
2018-07-06 03:05:22jaracosetmessages: + msg12044
2018-07-06 03:02:41jaracocreate