snowflake-R connection JDBC error

I am experiencing an error while setting up a JDBC connection between R and snowflake.
The error occurred after I ran my last command ( my_db <- ...) in the script.
My code:

### install Java JDK and set Java home directory
Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jdk-17.0.1\\")
Sys.getenv("JAVA_HOME")

install.packages(c("rJava"))
library(rJava)
.jinit()

install.packages(c("RJDBC", "DBI", "dplyr"))
library(RJDBC)
library(DBI)
library(dplyr)

install.packages("devtools")

### Rtools is required to build R packages before installing dplyr-snowflakedb
### install Rtools from https://cran.r-project.org/bin/windows/Rtools/ and write the path of rtools files in Document as a .Renviron file
write('PATH="C:\\rtools40\\usr\\bin"', file = "~/.Renviron", append = TRUE)
### test 
Sys.which('make')
install.packages("jsonlite", type = "source") # success!
### Delete the .Renviron file from Document

#update.packages(checkBuilt=TRUE) ### ignore this line of code, probably not necessary

### install dplyr.snowflakedb
devtools::install_github("snowflakedb/dplyr-snowflakedb", force = TRUE)

library(dplyr)
library(dplyr.snowflakedb)
### download snowflake-jdbc-3.13.9.jar and save in C:\Driver folder
options(dplyr.jdbc.classpath = "C:\\Driver\\snowflake-jdbc-3.13.9.jar")

### connect to snowflake
my_db <- src_snowflakedb(user = "USERNAME" , 
                         account = "DUMMYACCOUNT",
                         host = 'dummyhost.snowflakecomputing.com',
                         opts = list(authenticator = 'externalbrowser',
                                     warehouse = "WAREHOUSE",
                                     db='DATABASE',
                                     schema='SCHEMA'))


Error is:

Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set",  : 
  Unable to retrieve JDBC result set
  JDBC ERROR: JDBC driver internal error: Fail to retrieve row count for first arrow chunk: sun.misc.Unsafe or java.nio.DirectByteBuffer.<init>(long, int) not available.
  Statement: SELECT
    CURRENT_USER() AS USER,
    CURRENT_DATABASE() AS DBNAME,
    CURRENT_VERSION() AS VERSION,
    CURRENT_SESSION() AS SESSIONID

Could you please help me understand what this error means and how I can resolve it? Thank you!

Try disable arrow serialisation and see what happens, apparently the error is caused by arrow.

Potential solution posted online:
Refer to this question

Somehow this was corrected by using jdk-11...I wonder why...