Title: open(None) results in java.lang.ClassCastException
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
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.

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__(
        at org.python.core.PyFile$exposed___new__.createOfType(Unknown Source)
        at org.python.core.PyOverridableNew.new_impl(
        at org.python.core.PyType.invokeNew(
        at org.python.core.PyType.type___call__(
        at org.python.core.PyType.__call__(
        at org.python.core.OpenFunction.__call__(
        at org.python.core.PyObject.__call__(
        at org.python.core.PyObject.__call__(
        at org.python.pycode._pyx4.f$0(<stdin>:1)
        at org.python.pycode._pyx4.call_function(<stdin>)
        at org.python.core.Py.runCode(
        at org.python.core.Py.exec(
        at org.python.util.PythonInterpreter.exec(
        at org.python.util.InteractiveInterpreter.runcode(
        at org.python.util.InteractiveInterpreter.runsource(
        at org.python.util.InteractiveInterpreter.runsource(
        at org.python.util.InteractiveConsole.push(
        at org.python.util.InteractiveConsole._interact(
        at org.python.util.InteractiveConsole.interact(
        at org.python.util.jython.main(
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyNone cannot be cast to org.python.core.PyString

As a result, [code like this]( 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 `` has consistent behavior across Pythons.
Date User Action Args
2018-07-06 03:05:22jaracosetmessages: + msg12044
2018-07-06 03:02:41jaracocreate