find_package(JNI) not able to find JNI (cmake v 3.17)

I am getting error indicating failure to find JNI package while it is installed correctly in pretty standard location /opt/jdk/jdk8 (ubuntu 14.04, e.g /opt/jdk/jdk8/jre/lib/amd64/server/libjvm.so ) and JAVA_HOME variable is set appropriately before the call to find_package(JNI). the find_package(Java) called prior to find_package(JNI) successfully finds Java. The debug log for find_package(JNI) shows that instead of considering path set by JAVA_HOME it only considers /opt/myp, /opt/toolchains. This problems goes away after setting JAVA_AWT_LIBRARY, JAVA_JVM_LIBRARY, JAVA_INCLUDE_PATH, JAVA_INCLUDE_PATH2, JAVA_AWT_INCLUDE_PATH prior to calling find_package(JNI)
But such setting defeats the purpose of find_package(JNI) so I wonder if someone could suggest the fix.
Also the cmake.org description of FindJNI is too vague : “The caller may set variable JAVA_HOME to specify a Java installation prefix explicitly.”. This is unlike FindJAVA where the setting JAVA_HOME is specified. So what setting is needed to hint the location?

Sample CMake project
cmake_minimum_required(VERSION 3.17)
include(UseJava)
if(DEFINED ENV{JAVA_HOME})
    set(JAVA_HOME "$ENV{JAVA_HOME}")
else()
    set(JAVA_HOME /opt/jdk/jdk8)
endif()
message(STATUS "JAVA_HOME  variable is defined or set as '${JAVA_HOME}'")

 # set(JAVA_AWT_LIBRARY "${JAVA_HOME}/lib/amd64") #the path to the Java AWT Native Interface (JAWT) library
# set(JAVA_JVM_LIBRARY "${JAVA_HOME}/lib/amd64/server") #the path to the Java Virtual Machine (JVM) library
# set(JAVA_INCLUDE_PATH "${JAVA_HOME}/include")  #the include path to jni.h
# set(JAVA_INCLUDE_PATH2 "${JAVA_HOME}/include/linux") # the include path to jni_md.h and jniport.h
# set(JAVA_AWT_INCLUDE_PATH "${JAVA_HOME}/include")    # the include path to jawt.h
   #   set(CMAKE_FIND_ROOT_PATH "${JAVA_HOME}")
   #   set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH "${JAVA_HOME}")
   
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(JNI ) #TODO@ add REQUIRED, But cant use PATHS ${JAVA_HOME} as it triggers FindProjname.cmake mode
set(CMAKE_FIND_DEBUG_MODE FALSE)

if(JNI_FOUND)
    message (STATUS " JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
    message (STATUS " JNI_LIBRARIES=${JNI_LIBRARIES}")
else()
    message (STATUS " JNI is NOT FOUND")
endif()
Sample output
-- Found Java: /opt/jdk/jdk8/bin/java (found version "1.8.0.161") found components: Development 

-- JAVA_HOME  variable is defined or set as '/opt/jdk/jdk8'
CMake Debug Log at /opt/cmake/share/cmake-3.17/Modules/FindJNI.cmake:321 (find_library):
  find_library(JAVA_JVM_LIBRARY) removed original suffix
  /opt/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/home/cnh/build-scripts/
  from PATH_SUFFIXES while adding architecture paths for suffix '32'
Call Stack (most recent call first):
...myproj/src/CMakeLists.txt:30 (find_package)

CMake Debug Log at /opt/cmake/share/cmake-3.17/Modules/FindJNI.cmake:321 (find_library):
  find_library(JAVA_JVM_LIBRARY) added replacement path
  /opt/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/ to
  PATH_SUFFIXES for architecture suffix '32'
Call Stack (most recent call first):
  myproj/src/CMakeLists.txt:30 (find_package)
...
find_library called with the following settings:
VAR: JAVA_JVM_LIBRARY
    NAMES: "jvm"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1

  find_library considered the following locations:

    /opt/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/(lib)jvm(\.so|\.a)
    /opt/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/(lib)jvm(\.so|\.a)
    /opt/toolchains/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/lib/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/usr/sbin/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/usr/bin/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/sbin/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/bin/(lib)jvm(\.so|\.a)find
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/usr/local/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/usr/lib/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/usr/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/lib/(lib)jvm(\.so|\.a)
    /opt/myp/3.7.0/sysroots/cortexa9hf-vfp-neon-myp-linux-gnueabi/opt/(lib)jvm(\.so|\.a)

  The item was not found.
...and so on for other variables that supposed to be found...

Note: initially this issue was reported as a part of

Anyone more familiar with using Java/JNI in CMake projects able to offer any insights here? I can’t tell if this is a bug or perhaps just a doc issue.

It appears that behavior is influenced by setting CMAKE_TOOLCHAIN_FILE option in cmake (e.g. -DCMAKE_TOOLCHAIN_FILE=$ROOT/…/android.toolchain.cmake). However this file has not mentioning of any Java related variables, just C/C++/… options. It does set _CMAKE_TOOLCHAIN_PREFIX. Therefore I tried to set CMAKE_PREFIX_PATH (and Java_DIR ) to ${JAVA_HOME} prior to calling find_package. So it must be some other variable that force search off JAVA_HOME.
I had to move find_package(Java) to be before project() to ensure Java is Found ok. This is because cmake prefixes search path for Java by a toolchain path even though toolchain has nothing to do with Java (r. pnly C++/C/ASM). When find_package(Java) moved up before project() statement , cmake finds java correctly bc it sets CMAKE_PREFIX_PATH only after project(). Ensuring JAVA_HOME settings and find_package(Java) success is still not sufficient to make find_package(JNI) working without the kludge described above.
find_package(JNI) continues to prepend JNI file search path with a path specified by the toolchain path when -DCMAKE_TOOLCHAIN_FILE set. Attempts to reset CMAKE_FIND_USE_CMAKE_PATH: 0
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 0
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 0
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 0 lead to the same toolchain prefix combined with current source dir instead of patch specified by $JAVA_HOME

Probably when CMAKE_TOOLCHAIN_FILE and the toolchain .cmake file sets SYSTEM e.g:
include_directories( SYSTEM “${ANDROID_SYSROOT}/usr/include” ${ANDROID_STL_INCLUDE_DIRS} ) then this overrides $JAVA_HOME settings
for find_package(Java) find_package(JNI). Could cmake team confirm this please? Then a way to enforce $JAVA_HOME path would be to add it to include_directories( SYSTEM and documentation has to change appropriately for the FindJNI and Find.Java.