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

Reflection compatibility issues with Java 9 #1295

Closed
marat-gainullin opened this issue Jan 22, 2018 · 2 comments
Closed

Reflection compatibility issues with Java 9 #1295

marat-gainullin opened this issue Jan 22, 2018 · 2 comments
Labels

Comments

@marat-gainullin
Copy link

The following warnings occur while runnting tests on Java 9:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.cglib.core.ReflectUtils$2 (file:/C:/Users/mg/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-all/2.0.2-beta/3e24f450275812fb354d29a58b66b8f26e13002f/mockito-all-2.0.2-beta.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.mockito.cglib.core.ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

when running th following example:

package com.mockitotest;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.Set;

public class MockitoJava9ExampleTest {

    private static volatile ServletConfig config;

    @BeforeClass
    public static void setup() {
        ServletContext servletContext = Mockito.mock(ServletContext.class);
        Mockito.when(servletContext.getServletContextName()).thenReturn("mockito-java9");
        Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.enumeration(Set.of(
                "p1",
                "p2",
                "p3",
                "p4"
        )));
        Mockito.when(servletContext.getInitParameter("p1")).thenReturn("v1");
        Mockito.when(servletContext.getInitParameter("p2")).thenReturn("v2");
        Mockito.when(servletContext.getInitParameter("p3")).thenReturn("v3");
        Mockito.when(servletContext.getInitParameter("p4")).thenReturn("v4");
        Mockito.when(servletContext.getInitParameter("p5")).thenReturn("v5");
        config = Mockito.mock(ServletConfig.class);
        Mockito.when(config.getServletContext()).thenReturn(servletContext);
    }

    @AfterClass
    public static void tearDown() {
        config = null;
    }

    @Test
    public void runOnlyTest() {
        Mockito.mock(HttpServletRequest.class);
        Mockito.mock(HttpServletResponse.class);
    }
}

Environment :
Windows 10, Java 9, Mockito dependency: 'org.mockito:mockito-all:2.0.2-beta'

@TimvdLippe
Copy link
Contributor

TimvdLippe commented Jan 22, 2018 via email

@TimvdLippe
Copy link
Contributor

Closing per above comment. Feel free to reopen if you are still encountering this issue with the latest version of Mockito.

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

No branches or pull requests

3 participants