[Bug]: `compile()` with unrecognised flags raises a `ValueError` whose message crashes with `NullPointerException`
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #1232 来自 @jseop-lim —— 已合并
评估
调研方向
Start in graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java at CompileNode.checkFlags, then compare its raiseStatic call with the adjacent checkOptimize path and read the exception formatting path in ExceptionNodes.java. Reproduce with the supplied Python snippet and confirm that reading the caught ValueError message no longer crashes and matches compile(): unrecognised flags; check for a regression test covering the case.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
compile() with an unrecognised flags value raises a ValueError that can be caught, but reading its message (str(e), repr(e) or e.args) throws a Java NullPointerException and terminates the process.
Operating system
Linux
CPU architecture
x86_64
GraalPy version
25.0.2 (Python 3.12.8); also reproduced on 25.4.4.1.1 (Python 3.13.14) and on master 7e7182b103
JDK version
No response
Context configuration
No response
Steps to reproduce
try:
compile('1', 'f', 'exec', 0x7fffffff)
except ValueError as e:
print(e)
GraalPy master prints nothing and exits with the NullPointerException below (exit status 1; 25.0.2 exits with status 0).
Expected behavior
CPython 3.12.13 (same on 3.13.16):
compile(): unrecognised flags
Stack trace
java.lang.NullPointerException: Cannot invoke "com.oracle.truffle.api.strings.TruffleString.toJavaStringUncached()" because "format" is null
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodes$GetArgsNode.getFormattedMessage(ExceptionNodes.java:371)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodes$GetArgsNode.doManaged(ExceptionNodes.java:396)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodesFactory$GetArgsNodeGen$Inlined.executeAndSpecialize(ExceptionNodesFactory.java:1951)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.ExceptionNodesFactory$GetArgsNodeGen$Inlined.execute(ExceptionNodesFactory.java:1934)
at org.graalvm.py/com.oracle.graal.python.builtins.objects.exception.BaseExceptionBuiltins$StrNode.str(BaseExceptionBuiltins.java:511)
Additional context
The same crash happens for a bytes source, a negative flags, and the generic path (compile(None, 'f', 'exec', 0x10000)).
Root Cause
CompileNode.checkFlags raises with PRaiseNode.raiseStatic(this, ValueError, null, NO_VALUE, ErrorMessages.UNRECOGNIZED_FLAGS, PythonUtils.EMPTY_OBJECT_ARRAY) (BuiltinFunctions.java#L1143-L1148). That binds to the raiseStatic(Node, type, TruffleString message, Object... formatArgs) overload (PRaiseNode.java#L107-L112), so the exception gets a null message format, and formatting it lazily fails in ExceptionNodes.java#L370-L371. CPython sets a plain message (bltinmodule.c#L757-L763).
Fix Suggestion
Use the message overload, PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.UNRECOGNIZED_FLAGS), as checkOptimize next to it does.
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 163
- 平均合并
- 14 小时 10 分钟
- 30 天内合并 PR
- 56
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
oracle/graalpython 的其他 Issue
-
[Bug]: sys.flags.debug is 1 whenever optimization is off可能已有人在做 @hippi345 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
oracle/graalpython#1213 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
oracle/graalpython#1105 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
oracle/graalpython#1102 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
oracle/graalpython#1217 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 54/100
oracle/graalpython#1212 ·
维护者通常 1 天内回复
查看 oracle/graalpython 的全部 Issue
相似的 Issue
-
good first issue infrastructure
难度 2/5 1-3 小时 新手友好度 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
documentation priority: high
难度 2/5 1-3 小时 新手友好度 78/100
a-lex-s/mealie-telegram-bot#54 ·
维护者通常 1 天内回复
-
type/test
难度 2/5 1-3 小时 新手友好度 76/100
SaltedTan/virgil-language-server#218 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
btclib-org/btclib-wallet#541 ·
维护者通常 1 天内回复