Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-web-flux error with netty "Reflective setAccessible(true) disabled"

I have a junit test like above but when i launch test, i get this error (JDK 13.0.1):

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @4a94ee4

My tool is Intellij CE Edition 2019.3.1. This is my class and pom file:

    import org.junit.jupiter.api.Assertions;
    import org.junit.jupiter.api.Test;
    import org.springframework.web.reactive.function.client.WebClient;
    import reactor.core.publisher.Flux;

    class WebClientStockClientIntegrationTest {

        private static final String SYMBOL = "EUR";
        private WebClient webClient = WebClient.builder().build();

        @Test
        void shouldRetrieveStockPricesFromStockService() {
            WebClientStockClient webClientStockClient = new WebClientStockClient(webClient);
            Flux<StockPrice> prices = webClientStockClient.pricesFor(SYMBOL);
            Assertions.assertNotNull(prices);
            Assertions.assertTrue(prices.take(5).count().block() > 0);
        }
}

My pom with spring-boot and dependencies:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        ..

    <properties>
        <java.version>11</java.version>
    </properties>
like image 286
robyp7 Avatar asked Jan 25 '23 12:01

robyp7


1 Answers

I solved: I add :

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true

to my test configuration

enter image description here

like image 50
robyp7 Avatar answered Jan 30 '23 03:01

robyp7