From 0a2fe02acd89efacdb0f3b7bd7d31fc24184fdd2 Mon Sep 17 00:00:00 2001 From: Jeongseop Lim Date: Tue, 20 Oct 2026 12:02:44 +0900 Subject: [PATCH] Raise the compile() unrecognised-flags error with its message 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 --- .../src/tests/test_parser.py | 9 +++++++++ .../graal/python/builtins/modules/BuiltinFunctions.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_parser.py b/graalpython/com.oracle.graal.python.test/src/tests/test_parser.py index 5941b6668d..ba2991f4d1 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_parser.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_parser.py @@ -64,6 +64,15 @@ def test_incomplete_input_error(): assert False, "SyntaxError was not raised" +def test_compile_unrecognised_flags_message(): + try: + compile("1", "", "exec", 0x7fffffff) + except ValueError as e: + assert str(e) == "compile(): unrecognised flags" + else: + assert False, "ValueError was not raised" + + def test_lambdas_as_function_default_argument_values(): globs = {} exec(""" diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java index cd369906d2..0e8fa2320e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java @@ -1143,7 +1143,7 @@ private void checkOptimize(int optimize, Object kwOptimize) throws PException { @TruffleBoundary private void checkFlags(int flags) { if ((flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK)) != 0) { - throw PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY); + throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.UNRECOGNIZED_FLAGS); } }