Skip to content

Fix XRandR crash with no available displays and add JDK 8 compatibility for Buffer covariant return types - #170

Open
wayward-L wants to merge 1 commit into
LWJGL:masterfrom
wayward-L:fix/jdk8-compatibility-and-xrandr-crash
Open

wayward-L wants to merge 1 commit into
LWJGL:masterfrom
wayward-L:fix/jdk8-compatibility-and-xrandr-crash

Conversation

@wayward-L

Copy link
Copy Markdown

问题 1: XRandR 空数组崩溃

xrandr -q 返回无 connected 屏幕时,XRandR.java 的内部数据结构均为空,导致 ArrayIndexOutOfBoundsException

  • findPrimary()screens[0] 在空数组上越界
  • getResolutions()screens.get(name).clone() 对 null 调用
  • DisplayModetoScreen() / ScreentoDisplayMode() — 未处理 findPrimary() 返回 null

修复:在所有方法中增加了空检查和 null 安全 fallback。

问题 2: JDK 8 NoSuchMethodError

ByteBuffer.flip() 在 Java 9+ 中新增协变返回类型(返回 ByteBuffer 而非 Buffer)。
部分 JDK 8 发行版(如 Oracle JDK 1.8.0_441)在 rt.jar 中包含了此协变签名,编译器据此
生成字节码引用 ByteBuffer.flip()Ljava/nio/ByteBuffer;,而标准 JDK 8 虚拟机无此方法,
运行时抛出 NoSuchMethodError

修复:对项目中所有 ByteBuffer/CharBuffer 变量上的 .flip().clear().rewind()
.limit(int).position(int) 调用,通过 (Buffer) 转型强制编译出兼容 JDK 8 的字节码。

修改统计:

  • 28 个源文件,~80 处调用点
  • 包括:Linux/X11 和 macOS/Windows 各平台的事件队列、键盘、鼠标模块
  • OpenCL 和 GLES 的 API 工具类

验证:

  • ant jars — BUILD SUCCESSFUL,0 错误
  • 字节码验证:javap 确认所有 flip() 调用目标为 Buffer.flip()Ljava/nio/Buffer;
  • XRandR 所有公共方法均进行了空数组保护

…ty for Buffer covariant return types

Fix ArrayIndexOutOfBoundsException in XRandR when xrandr -q returns
no connected screens by adding null/empty checks in findPrimary(),
getResolutions(), ScreentoDisplayMode() and DisplayModetoScreen().
Fall back to default DisplayMode when no screen data is available.

Add explicit (Buffer) casts on ByteBuffer/CharBuffer method calls
(flip(), clear(), rewind(), limit(), position()) used in Java 9+
with covariant return types. When compiled with JDK 8 builds that
include these backported signatures, the bytecode would reference
ByteBuffer.flip()Ljava/nio/ByteBuffer; which does not exist at
runtime on standard JDK 8 JVMs, causing NoSuchMethodError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant