Snappy error: Failed to modify class loader field 'sys_paths'

Hi everyone,

After getting all the dependencies for snappy installed, I tried snappy itself out by calling snappy from Python in the ~/.snap/snap-python/ folder and got the error:

SEVERE: org.esa.snap.runtime.Engine: Failed to modify class loader field 'sys_paths'

java.lang.NoSuchFieldException: sys_paths

I could not find any solution for this using Google or by searching these forums. Can anyone point me to a solution?

OS: Ubuntu 19.04, 64 bit
Python version: 3.7.3
Java:
openjdk version “13” 2019-09-17
OpenJDK Runtime Environment (build 13+13-Ubuntu-0ubunt1)
OpenJDK 64-Bit Server VM (build 13+13-Ubuntu-0ubunt1, mixed mode, sharing)

Full error message:

Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snappy import ProductIO
SEVERE: org.esa.snap.runtime.Engine: Failed to modify class loader field 'sys_paths'
java.lang.NoSuchFieldException: sys_paths
	at java.base/java.lang.Class.getDeclaredField(Class.java:2418)
	at org.esa.snap.runtime.Engine.setJavaLibraryPath(Engine.java:286)
	at org.esa.snap.runtime.Engine.setJavaLibraryPath(Engine.java:265)
	at org.esa.snap.runtime.Engine.<init>(Engine.java:46)
	at org.esa.snap.runtime.Engine.start(Engine.java:117)
	at org.esa.snap.runtime.Engine.start(Engine.java:90)

SEVERE: org.esa.s2tbx.dataio.gdal.activator.GDALPlugInActivator: java.lang.NoSuchFieldException: Invalid field : sys_paths
java.lang.RuntimeException: java.lang.NoSuchFieldException: Invalid field : sys_paths
	at org.esa.snap.utils.NativeLibraryUtils.registerNativePaths(NativeLibraryUtils.java:58)
	at org.esa.snap.utils.NativeLibraryUtils.registerNativePaths(NativeLibraryUtils.java:34)
	at org.esa.s2tbx.dataio.gdal.GDALInstaller.copyDistribution(GDALInstaller.java:163)
	at org.esa.s2tbx.dataio.gdal.activator.GDALDistributionInstaller.install(GDALDistributionInstaller.java:56)
	at org.esa.s2tbx.dataio.gdal.activator.GDALPlugInActivator.start(GDALPlugInActivator.java:22)
	at org.esa.snap.runtime.Engine.informActivators(Engine.java:222)
	at org.esa.snap.runtime.Engine.lambda$start$0(Engine.java:121)
	at org.esa.snap.runtime.Engine.runClientCode(Engine.java:189)
	at org.esa.snap.runtime.Engine.start(Engine.java:121)
	at org.esa.snap.runtime.Engine.start(Engine.java:90)
Caused by: java.lang.NoSuchFieldException: Invalid field : sys_paths
	at org.esa.snap.utils.PrivilegedAccessor.getField(PrivilegedAccessor.java:181)
	at org.esa.snap.utils.PrivilegedAccessor.getField(PrivilegedAccessor.java:185)
	at org.esa.snap.utils.PrivilegedAccessor.getField(PrivilegedAccessor.java:185)
	at org.esa.snap.utils.PrivilegedAccessor.setStaticValue(PrivilegedAccessor.java:88)
	at org.esa.snap.utils.NativeLibraryUtils.registerNativePaths(NativeLibraryUtils.java:56)
	... 9 more

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/home/jelle/esa-snap/snap/modules/ext/org.esa.snap.snap-jython/org-python/jython-standalone.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
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
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.

Without looking into OpenJDK, I guess the field ‘sys_paths’ does not exist in the class ClassLoader in OpenJDK. Probably it exists only in the Oracle JDK/JRE.
Currently SNAP is only compatible with the Oracle JRE 1.8_u202. It is planned for the next release to use a recent OpenJDK.

@oana_hogoiu The class NativeLibraryUtils needs revision when we switch to OpenJDK.

Thank you for the quick reponse! I will try this out as soon as possible.

I needed to reinstall jpy after installing the Oracle JRE, but it gives an error that it cannot find Java, even though my JAVA_HOME is set to the proper path:

$pip3 install https://github.com/bcdev/jpy/archive/master.zip
Collecting https://github.com/bcdev/jpy/archive/master.zip
  Downloading https://github.com/bcdev/jpy/archive/master.zip
 / 1.4MB 1.2MB/s
Complete output from command python setup.py egg_info:
Error: environment variable "JAVA_HOME" must be set to a JDK (>= v1.7) installation directory
Note that you can use non-standard global option [--maven] to force a Java Maven build for the jpy Java API

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-m0_zjer8/

My Java version:

    $java -version
    java version "1.8.0_202"
    Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
    Java HotSpot(TM) Server VM (build 25.202-b08, mixed mode)

And my ~/.bashrc:
export JAVA_HOME=/usr/lib/jvm/jre1.8.0_202

When using the JDK download on the same page, I got the following error:

$ pip3 install https://github.com/bcdev/jpy/archive/master.zip
Collecting https://github.com/bcdev/jpy/archive/master.zip
  Downloading https://github.com/bcdev/jpy/archive/master.zip
     \ 4.4MB 1.9MB/s
    Complete output from command python setup.py egg_info:
    Error: Cannot find any JVM shared library
    Note that you can use non-standard global option [--maven] to force a Java Maven build for the jpy Java API
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-l5i2jlag/

Even though JAVA_HOME was set correctly again (and ~/.bashrc was reloaded)

jpy does get installed properly when using JDK 13 (link) and pointing the java home to export JDK_HOME=/usr/lib/jvm/jdk-13 and appending the bin directory to path: export PATH=/usr/lib/jvm/jdk-13/bin:$PATH

However, the original sys_paths error appears again when doing from snappy import ProductIO

So with jdk-8u202 I cannot install jpy and with jdk-13 I get the sys_paths error. The best way to fix this would be to fix the jpy installation, but how?