browserstack / browserstack-local-java

Java bindings for BrowserStack Local
https://www.browserstack.com
MIT License
18 stars 34 forks source link

can't catch `LocalException`: tried to access class com.browserstack.local.LocalException #46

Open SlavikCA opened 4 years ago

SlavikCA commented 4 years ago

Using version 1.0.3

I have this Groovy code:

import com.browserstack.local.LocalException

class AcsTestBase {
...
        log.info 'Starting BrowserStack Local binary ...'
        try {
            bsLocal = new Local()
            HashMap<String, String> bsLocalArgs = new HashMap<String, String>()
            bsLocalArgs.put('key', key)
            bsLocal.start(bsLocalArgs)
            log.info 'bsLocal.isRunning(): ' + bsLocal.isRunning()
        } catch (LocalException e) {
            log.error e.message
            throw e
        }

This results in this:

java.lang.IllegalAccessError: tried to access class com.browserstack.local.LocalException from class tests.AcsTestBase

But if I use catch (Exception e) instead, then everything is working ok: I'm getting message in the log, as expected.

The point of this issue is not fact, that I'm getting Exception, but the issue is that I can't catch the exception by using LocalException class

By the way, the cause of exception was this (I know how to handle it):

com.browserstack.local.LocalException: Either another browserstack local client is running on your machine or some server is listening on port 45691
    at com.browserstack.local.Local.start(Local.java:80)
    at com.browserstack.local.Local$start.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
...
stevenmchaves commented 2 years ago

I also opened up basically the same:

https://github.com/browserstack/browserstack-local-java/issues/67

The class should be public.