cbfiddle / Issues

0 stars 0 forks source link

UnsatisfiedLinkError if I try to install a default menu bar #7

Open hakanai opened 5 years ago

hakanai commented 5 years ago

We try to make our application look slightly more native by setting a default menu bar to the screen.

But if I try to do this with VAqua installed, I get an UnsatisfiedLinkError.

java.lang.UnsatisfiedLinkError: com.apple.laf.ScreenMenu.addMenuListeners(Lcom/apple/laf/ScreenMenu;J)J
    at com.apple.laf.ScreenMenu.addMenuListeners(Native Method)
    at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:254)
    at java.awt.Menu.addNotify(Menu.java:183)
    at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:234)
    at com.apple.laf.ScreenMenuBar.add(ScreenMenuBar.java:285)
    at com.apple.laf.ScreenMenuBar.addSubmenu(ScreenMenuBar.java:223)
    at com.apple.laf.ScreenMenuBar.addNotify(ScreenMenuBar.java:66)
    at com.apple.eawt._AppMenuBarHandler.installDefaultMenuBar(_AppMenuBarHandler.java:116)
    at com.apple.eawt._AppMenuBarHandler.setDefaultMenuBar(_AppMenuBarHandler.java:71)
    at com.apple.eawt.Application.setDefaultMenuBar(Application.java:384)
    at ...application code...
cbfiddle commented 5 years ago

The way that the screen menu bar is implemented in the JDK requires that Aqua LAF be loaded.

On Sep 25, 2019, at 4:50 PM, Trejkaz (pen name) notifications@github.com wrote:

We try to make our application look slightly more native by setting a default menu bar to the screen.

But if I try to do this with VAqua installed, I get an UnsatisfiedLinkError.

java.lang.UnsatisfiedLinkError: com.apple.laf.ScreenMenu.addMenuListeners(Lcom/apple/laf/ScreenMenu;J)J at com.apple.laf.ScreenMenu.addMenuListeners(Native Method) at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:254) at java.awt.Menu.addNotify(Menu.java:183) at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:234) at com.apple.laf.ScreenMenuBar.add(ScreenMenuBar.java:285) at com.apple.laf.ScreenMenuBar.addSubmenu(ScreenMenuBar.java:223) at com.apple.laf.ScreenMenuBar.addNotify(ScreenMenuBar.java:66) at com.apple.eawt._AppMenuBarHandler.installDefaultMenuBar(_AppMenuBarHandler.java:116) at com.apple.eawt._AppMenuBarHandler.setDefaultMenuBar(_AppMenuBarHandler.java:71) at com.apple.eawt.Application.setDefaultMenuBar(Application.java:384) at ...application code... — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cbfiddle/Issues/issues/7?email_source=notifications&email_token=ABSSJGKHIHAMTYF4APD5HRDQLP2L3A5CNFSM4I2THMOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HNXV6VA, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSSJGOV6MIXSVZ36IKO6WDQLP2L3ANCNFSM4I2THMOA.

hakanai commented 5 years ago

Ah, that's... something I had no idea about. I thought I had seen it working with one of the other L&Fs, but I can't remember how long ago it was, so it may have changed since.

Rats, so that blocks using VAqua entirely unless I can dodge it somehow... like convincing Aqua to load whatever it needs to load first, and then loading VAqua maybe.

cbfiddle commented 5 years ago

I’m not having any problem with the system menu bar and I’m not aware of doing anything explicit to load Aqua.

Are you doing something to prevent Aqua from loading?

On Sep 25, 2019, at 6:52 PM, Trejkaz (pen name) notifications@github.com wrote:

Ah, that's... something I had no idea about. I thought I had seen it working with one of the other L&Fs, but I can't remember how long ago it was, so it may have changed since.

Rats, so that blocks using VAqua entirely unless I can dodge it somehow... like convincing Aqua to load whatever it needs to load first, and then loading VAqua maybe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbfiddle/Issues/issues/7?email_source=notifications&email_token=ABSSJGPTVIY43QPFBABQNYDQLQIWHA5CNFSM4I2THMOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7T7I6A#issuecomment-535295096, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSSJGJOHMJQD7GMFM27UUDQLQIWHANCNFSM4I2THMOA.

hakanai commented 5 years ago

Nothing that I'm aware of, other than setting VAqua as the LAF instead of Aqua. I'll have to try reducing what we're doing to a smaller program to get an idea of what is breaking. The only slightly different thing is that we're using Gum to make the actual calls to Application, but it's just a thin layer which calls straight through to Apple's API.

cbfiddle commented 5 years ago

It looks like the problem is failure to load a native library:

java.lang.UnsatisfiedLinkError: com.apple.laf.ScreenMenu.addMenuListeners(Lcom/apple/laf/ScreenMenu;J)J at com.apple.laf.ScreenMenu.addMenuListeners(Native Method) at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:254) at java.awt.Menu.addNotify(Menu.java:183) at com.apple.laf.ScreenMenu.addNotify(ScreenMenu.java:234) at com.apple.laf.ScreenMenuBar.add(ScreenMenuBar.java:285) at com.apple.laf.ScreenMenuBar.addSubmenu(ScreenMenuBar.java:223) at com.apple.laf.ScreenMenuBar.addNotify(ScreenMenuBar.java:66) at com.apple.eawt._AppMenuBarHandler.installDefaultMenuBar(_AppMenuBarHandler.java:116) at com.apple.eawt._AppMenuBarHandler.setDefaultMenuBar(_AppMenuBarHandler.java:71) at com.apple.eawt.Application.setDefaultMenuBar(Application.java:384) at ...application code...

On Sep 25, 2019, at 11:21 PM, Trejkaz (pen name) notifications@github.com wrote:

Nothing that I'm aware of, other than setting VAqua as the LAF instead of Aqua. I'll have to try reducing what we're doing to a smaller problem to get an idea of what is breaking. The only slightly different thing is that we're using Gum to make the actual calls to Application, but it's just a thin layer which calls straight through to Apple's API.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbfiddle/Issues/issues/7?email_source=notifications&email_token=ABSSJGPHYKOYAWP2BLNVKKTQLRIFVA5CNFSM4I2THMOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7UOJYY#issuecomment-535356643, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSSJGOJL4EYIQMXNB7MCSLQLRIFVANCNFSM4I2THMOA.

hakanai commented 5 years ago

Indeed, it looks like Apple's AquaLookAndFeel is loading some native library which VAqua's replacement AquaLookAndFeel is not loading.

So the workaround at the moment is I subclass it to override the initialisation logic:

    @Override
    public void initialize()
    {
        super.initialize();

        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
            System.loadLibrary("osxui");
            return null;
        });
    }

Edit: Nope, spoke too soon. It loads the library fine but fails in the same way. There must be another native library buried in another class in the same area.

cbfiddle commented 5 years ago

This is what I am doing that has the equivalent effect:

UIManager.getLookAndFeel()

On Sep 26, 2019, at 4:06 PM, Trejkaz (pen name) notifications@github.com wrote:

Indeed, it looks like Apple's AquaLookAndFeel is loading some native library which VAqua's replacement AquaLookAndFeel is not loading.

So the workaround at the moment is I subclass it to override the initialisation logic:

@Override
public void initialize()
{
    super.initialize();

    AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
        System.loadLibrary("osxui");
        return null;
    });
}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbfiddle/Issues/issues/7?email_source=notifications&email_token=ABSSJGIHBKTY3GDGGUPFKFLQLU6A3A5CNFSM4I2THMOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7XGSUI#issuecomment-535718225, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSSJGIRTCBP3OGT3PWT2C3QLU6A3ANCNFSM4I2THMOA.

hakanai commented 5 years ago

Yep, so I guess this works - programmatically load Aqua and then immediately switch it out for VAqua.

cbfiddle commented 5 years ago

This is actually a bug that was fixed in JDK 9.

See JDK-8166683 https://bugs.openjdk.java.net/browse/JDK-8166683.

I should find a way for VAqua to work around this problem in JDK 8.

On Sep 25, 2019, at 11:21 PM, Trejkaz (pen name) notifications@github.com wrote:

Nothing that I'm aware of, other than setting VAqua as the LAF instead of Aqua. I'll have to try reducing what we're doing to a smaller problem to get an idea of what is breaking. The only slightly different thing is that we're using Gum to make the actual calls to Application, but it's just a thin layer which calls straight through to Apple's API.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbfiddle/Issues/issues/7?email_source=notifications&email_token=ABSSJGPHYKOYAWP2BLNVKKTQLRIFVA5CNFSM4I2THMOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7UOJYY#issuecomment-535356643, or mute the thread https://github.com/notifications/unsubscribe-auth/ABSSJGOJL4EYIQMXNB7MCSLQLRIFVANCNFSM4I2THMOA.

hakanai commented 5 years ago

Interesting, we're only jumping to VAqua because we want to move to JDK 9 later, which makes this incompatibility not an issue for us anyway. It just means that we have to do the switch to VAqua only on our JDK 9 branch.