Skip to content

Fix compile() unrecognised-flags ValueError crashing on its message - #1232

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:GH-1231-compile-flags-message
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:GH-1231-compile-flags-message

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Fixes #1231

checkFlags called raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY), which binds to the (Node, type, TruffleString message, Object...) overload, so the exception had a null message format. Catching it worked, but reading its message threw a Java NullPointerException.

AS-IS

>>> try:
...     compile('1', 'f', 'exec', 0x7fffffff)
... except ValueError as e:
...     print(e)
...
java.lang.NullPointerException: Cannot invoke "com.oracle.truffle.api.strings.TruffleString.toJavaStringUncached()" because "format" is null

TO-BE

compile(): unrecognised flags

(matching CPython)

Changes

  • Raise with raiseStatic(this, ValueError, ErrorMessages.UNRECOGNIZED_FLAGS), as checkOptimize next to it does.
  • Add test_compile_unrecognised_flags_message to tests/test_parser.py.

Testing

mx python-jvm on linux-aarch64, then mx graalpytest test_parser.py test_exec.py test_ast.py test_code.py (108 passed). test.test_compile and test.test_builtin from lib-python report the same failures and errors as on master. The new test crashes on the unpatched build. A str, a bytes and a None source with bad flags now print the same message and args as CPython 3.12.13.

checkFlags called PRaiseNode.raiseStatic(this, ValueError, null,
NO_VALUE, UNRECOGNIZED_FLAGS, EMPTY_OBJECT_ARRAY), mirroring the
argument order of the old internal execute(). No public overload takes
those arguments, so the call bound to raiseStatic(Node, type, message,
Object...) with a null message and the intended message as a format
argument. The ValueError could be caught, but str(), repr() or .args on
it formatted the null message and threw a Java NullPointerException.

Use the message overload, as checkOptimize next to it does. CPython
raises ValueError("compile(): unrecognised flags").

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: compile() with unrecognised flags raises a ValueError whose message crashes with NullPointerException

1 participant