0

I'm using the BrowserLauncher2 library for opening the user's default web browser from my Swing app, but it's throwing a very confusing exception:

public static void openURL(String url) {
        try{
            BrowserLauncher launcher = new BrowserLauncher();
            launcher.openURLinBrowser(url);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

Exception:

edu.stanford.ejalbert.exception.BrowserLaunchingExecutionException: java.lang.reflect.InvocationTargetException
    at edu.stanford.ejalbert.launching.macos.MacOs3_1BrowserLaunching.openUrl(MacOs3_1BrowserLaunching.java:61)
    at edu.stanford.ejalbert.BrowserLauncherRunner.run(BrowserLauncherRunner.java:136)
    at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at edu.stanford.ejalbert.launching.macos.MacOs3_1BrowserLaunching.openUrl(MacOs3_1BrowserLaunching.java:58)
    ... 2 more
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission canOpenURLs)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
    at java.security.AccessController.checkPermission(AccessController.java:427)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at com.apple.eio.FileManager.openURL(FileManager.java:229)
    at com.apple.mrj.MRJPriv.openURL(MRJPriv.java:255)
    at com.apple.mrj.MRJFileUtils.openURL(MRJFileUtils.java:206)
    ... 7 more

4 Answers 4

1

You are running your application with a SecurityManager set. Some code in the AccessControlContext (a.k.a. acc) does not have the required permission. Probably that code is your application code.

1

An InvocationTargetException always wraps another exception which was caused while invoking a method or constructor via reflection. To solve your problem, you need to look at the exception under it, the IllegalAccessException which as Tom Hawtin points out, is being thrown because of the SecurityManager.

0

First of all, BrowserLauncher does not support Mac OS < 10.2.

Also, on MacOS, BrowserLauncher launches the default browser, targeting a specific browser is not possible. You could try changing the default browser on your computer to see if that helps. Apparently this can be done by the following: Start Safari -> Select Preferences -> in the General tab, find the Default web browser.

0

I was getting AccessControlExceptions with BrowserLauncher2 via an applet of mine. Your situation may be similar, because you are running your app with a SecurityManager.

I solved my problem by signing the BrowserLauncher2 jar with my certificate. If your user accepts your certificate, BrowserLauncher should have the permissions it needs to do its job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.