如何访问 `AWTAccessor.getCursorAccessor().setPData()`

How to access `AWTAccessor.getCursorAccessor().setPData()`

我正在尝试 运行 AWTAccessor.getCursorAccessor().setPData(this, cursor); 进行 class sun.awt.AWTAccessor.

的游标相关操作

我遇到错误:

Exception in thread "main" java.lang.IllegalAccessError: class xawtcursor.XImageCursor (in unnamed module @0x3d3fcdb0) cannot access class sun.awt.AWTAccessor (in module java.desktop) because module java.desktop does not export sun.awt to unnamed module @0x3d3fcdb0
    at xawtcursor.XImageCursor.createNativeCursor(XImageCursor.java:25)
    ...

部分测试代码(此处1无效,只是为了简化测试代码,方便复现):

package xawtcursor;

import sun.awt.AWTAccessor;
import sun.awt.X11.XCustomCursor;
import sun.awt.X11.XToolkit;

import java.awt.*;

public class XImageCursor extends XCustomCursor {
    public XImageCursor(Image cursor, Point hotSpot, String name) throws IndexOutOfBoundsException {
        super(cursor, hotSpot, name);
    }

    protected void createNativeCursor(Image im, int[] pixels, int width, int height, int xHotSpot, int yHotSpot) {
        XToolkit.awtLock();
        try {
            AWTAccessor.getCursorAccessor().setPData(this, 1);
        } finally {
            XToolkit.awtUnlock();
        }
    }
}

我尝试了 --add-exports=java.desktop/sun.awt.X11=ALL-UNNAMED 修复了一个错误。让我访问这个的编译选项是什么?

原来我只需要添加多个 --add-exports 选项。添加以下作品:

--add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=java.desktop/sun.awt.X11=ALL-UNNAMED