Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method open() throws IllegalAccessException #92

Open
IZaiarnyi opened this issue Dec 12, 2019 · 4 comments
Open

Method open() throws IllegalAccessException #92

IZaiarnyi opened this issue Dec 12, 2019 · 4 comments

Comments

@IZaiarnyi
Copy link

    @Test
    public void openSearchPage(){
        google.onSearchPage().open();
    }
java.lang.reflect.UndeclaredThrowableException
	at com.sun.proxy.$Proxy12.open(Unknown Source)
	at Tests.openSearchPage(Tests.java:27)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.privateRun(TestRunner.java:648)
	at org.testng.TestRunner.run(TestRunner.java:505)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
	at org.testng.TestNG.runSuites(TestNG.java:1049)
	at org.testng.TestNG.run(TestNG.java:1017)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.IllegalAccessException: access to public member failed: io.qameta.atlas.webdriver.WebPage.open[Ljava.lang.Object;@2a898881/invokeSpecial, from io.qameta.atlas.webdriver.WebPage/2 (unnamed module @2f40e5db)
	at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:942)
	at java.base/java.lang.invoke.MethodHandles$Lookup.checkAccess(MethodHandles.java:2212)
	at java.base/java.lang.invoke.MethodHandles$Lookup.checkMethod(MethodHandles.java:2152)
	at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:2296)
	at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodNoSecurityManager(MethodHandles.java:2289)
	at java.base/java.lang.invoke.MethodHandles$Lookup.unreflectSpecial(MethodHandles.java:1804)
	at io.qameta.atlas.core.internal.DefaultMethodExtension.invoke(DefaultMethodExtension.java:27)
	at io.qameta.atlas.core.internal.AtlasMethodHandler.invokeWithRetry(AtlasMethodHandler.java:65)
	at io.qameta.atlas.core.internal.AtlasMethodHandler.invoke(AtlasMethodHandler.java:41)
	... 26 more


Please find the code from example bellow:
test.zip

@PavelSukh
Copy link

I join the message above - I start the project using maven from the command line (mvn clean test) and get an IllegalAccessException error.
My project: https://github.com/PavelSukh/example.git

@rgrigoryev
Copy link

rgrigoryev commented Feb 9, 2020

@PavelSukh, it seems io.qameta.htmlelements is not ready for java 9+. I found hacky workaround. Add io.qameta.htmlelements.extension.DefaultMethod.java to your project source directory in order to "overwrite" library implementation. Put this implementation there:

...
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@HandleWith(DefaultMethod.Extension.class)
public @interface DefaultMethod {

    class Extension implements MethodHandler {

        @Override
        public Object handle(Context context, Object proxy, Method method, Object[] args) throws Throwable {
            Class<?> declaringClass = method.getDeclaringClass();
            if (isJava8()) {
                Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class
                        .getDeclaredConstructor(Class.class, int.class);
                constructor.setAccessible(true);
                return constructor.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE)
                        .unreflectSpecial(method, declaringClass)
                        .bindTo(proxy)
                        .invokeWithArguments(args);
            } else {
                MethodType rt = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
                return MethodHandles.lookup()
                        .findSpecial(declaringClass, method.getName(), rt, declaringClass)
                        .bindTo(proxy)
                        .invokeWithArguments(args);
            }
        }

        private static boolean isJava8() {
            String version = ManagementFactory.getRuntimeMXBean().getSpecVersion();
            return version.startsWith("1.8");
        }
    }

}

@PavelSukh
Copy link

@rgrigoryev thank you for your help. I was deleted JDK 11 from my pc and use the JDK 8 on default, it solved my problem.

@Petrusiova
Copy link

@rgrigoryev thank you for your help. I was deleted JDK 11 from my pc and use the JDK 8 on default, it solved my problem.

Solved the same problem using the same way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants