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
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题 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 的字节码。修改统计:
验证:
ant jars— BUILD SUCCESSFUL,0 错误javap确认所有flip()调用目标为Buffer.flip()Ljava/nio/Buffer;XRandR所有公共方法均进行了空数组保护