skip to Main Content

I was trying to implement Redis caching for SpringBoot app which exposes Rest API. Important code snippets and maven build file enclosed.

Start-up annotations:

@SpringBootApplication
@EnableAsync
@EnableScheduling
@EnableCaching
public class Application {

pom.xml(Only relevant dependencies listed) :

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.10</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.9.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

Running from IntelliJ IDE environment.

  • Project SDK : Java 11
  • Project Language Level : 11

At project start-up I am encountering below exception but start-up completes successfully. What is the root cause of the exception and how I can solve it?

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
    at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
    at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:233)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:227)
    at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:109)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:218)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:197)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:179)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:163)
    at io.lettuce.core.resource.DefaultClientResources.<init>(DefaultClientResources.java:167)
    at io.lettuce.core.resource.DefaultClientResources$Builder.build(DefaultClientResources.java:530)
    at io.lettuce.core.resource.DefaultClientResources.create(DefaultClientResources.java:231)
    at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.lettuceClientResources(LettuceConnectionConfiguration.java:66)
    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:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.iyzico.challenge.Application.main(Application.java:18)

2020-09-24 12:25:24.039 DEBUG 56915 --- [           main] i.n.util.internal.PlatformDependent0     : java.nio.Bits.unaligned: available, true
2020-09-24 12:25:24.040 DEBUG 56915 --- [           main] i.n.util.internal.PlatformDependent0     : jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable

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 @21ba2445
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
    at java.base/java.lang.reflect.Method.invoke(Method.java:558)
    at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:347)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:338)
    at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:109)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:218)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:197)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:179)
    at io.netty.util.HashedWheelTimer.<init>(HashedWheelTimer.java:163)
    at io.lettuce.core.resource.DefaultClientResources.<init>(DefaultClientResources.java:167)
    at io.lettuce.core.resource.DefaultClientResources$Builder.build(DefaultClientResources.java:530)
    at io.lettuce.core.resource.DefaultClientResources.create(DefaultClientResources.java:231)
    at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.lettuceClientResources(LettuceConnectionConfiguration.java:66)
    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:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.iyzico.challenge.Application.main(Application.java:18)

Thanks in advance

2

Answers


  1. As per https://github.com/netty/netty/issues/7817 "It’s not an error, it’s a debug message with a stacktrace, change your logger level to something else apart from debug eg. info or warn."

    You need to change your logger level of this package to suppress these warnings.

    Add this line below in your logback-spring.xml to suppress all messages.

    <logger name="io.netty.util" level="ERROR"/>
    
    Login or Signup to reply.
  2. I fix it by adding this to JVM args

    –add-opens java.base/jdk.internal.misc=ALL-UNNAMED –add-opens java.base/java.nio=ALL-UNNAMED –add-opens java.base/java.security=ALL-UNNAMED –add-opens jdk.unsupported/sun.misc=ALL-UNNAMED –add-opens java.base/sun.security.action=ALL-UNNAMED –add-opens jdk.naming.rmi/com.sun.jndi.rmi.registry=ALL-UNNAMED –add-opens java.base/sun.net=ALL-UNNAMED –add-opens java.base/java.lang=ALL-UNNAMED –add-opens java.base/java.lang.reflect=ALL-UNNAMED

    these args may have other that is not related to this problem, but I can not pick them out

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search