Pivotal Knowledge Base

Follow

ERROR: java.lang.NoClassDefFoundError: Could not initialize class sun.security.provider.NativePRNG

Environment

Product Version
Pivotal Greenplum 4.2.x
OS RHEL 6.x

Problem:

Executing a function created using PL/JAVA fails can fail with an error similar to below:

Executing the function 1st time gives an error similar to:
cbl=# select java_get_key('abc');
ERROR: java.lang.ExceptionInInitializerError (JNICalls.c:70)

Subsequent execution indicates NoClassDefFoundError exception:
cbl=# select java_get_key('abc');
ERROR: java.lang.NoClassDefFoundError: Could not initialize class sun.security.provider.NativePRNG (JNICalls.c:70)

Cause:

PL/Java is a TRUSTED language. PostgreSQL stipulates that a language marked as trusted has no access to the filesystem and PL/Java enforces this. Any user can create and access functions or triggers in a trusted language. 

PL/Java also installs a language handler for the language "javaU". This version is not trusted and only a superuser can create new functions that use it. Any user can still call the functions.
More details on: https://github.com/tada/pljava/wiki

Database logs available under $MASTER_DATA_DIRECTORY/pg_log must be searched for any error during the execution of the function. In this case, the below error message indicates that /dev/random file can't be read during the execution of the function.

2014-07-04 11:10:16.113551 PDT,,,p480393,th699058016,,,,0,,,seg-1,,,,,"LOG","00000","3rd party error log:
at com.pivotal.cv.common.PivotalCrypto.encrypt(PivotalCrypto.java:41)",,,,,,,,"SysLoggerMain","syslogger.c",520,
2014-07-04 11:10:16.113654 PDT,,,p480393,th699058016,,,,0,,,seg-1,,,,,"LOG","00000","3rd party error log:",,,,,,,,"SysLoggerMain","syslogger.c",520,
2014-07-04 11:10:16.114333 PDT,,,p480393,th699058016,,,,0,,,seg-1,,,,,"LOG","00000","3rd party error log:
Caused by: java.lang.SecurityException: read on /dev/random",,,,,,,,"SysLoggerMain","syslogger.c",520,

/dev/random is a special file which provide an interface to the kernel's random number generator and cannot be used by trusted languages. Any function which uses system files like /dev/random should be created using untrusted version of the language, ex. PL/JAVAU.

Fix:

Step 1. Verify if PL/JAVAU is already available, if not, create PL/JAVAU language.

Below output indicates it's already installed.
gpadmin=# select * from pg_language where lanname = 'pljavau';
lanname | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl
---------+---------+--------------+---------------+--------------+--------
pljavau |    t    |       f    | 16562        |       0      |
If pljavau is not available, create it using below:
psql -d <dbname> -c "CREATE LANGUAGE pljavau"

Step 2: Recreate the function using PLJAVAU as a superuser. Example:

CREATE OR REPLACE FUNCTION java_get_key(bytea)
RETURNS bytea AS 'com.pivotal.cv.common.PivotalCrypto.rawEncrypt'
LANGUAGE pljavau VOLATILE;

Step 3: Verify by executing the function again. Example:

gpadmin=# select java_get_key('abc');
java_get_key
---------------------------
5M\x0C\x12&gHo\x10c

Comments

  • Avatar
    Kushal Choubay

    Found similar issue where classpath was not set. Need to set classpath to avoid the below issue

    Error:
    ERROR: java.lang.ClassNotFoundException: org.postgresql.example.ComplexScalar (JNICalls.c:70)
    #######################################
    2015-06-23 12:19:22.641043 EDT,"gpadmin","prqa",p421880,th1068791552,"[local]",,2015-06-23 11:17:15 EDT,26914948,,cmd12687,seg-1,,,x26914948,sx1,"ERROR","XX000","java.lang.ClassNotFoundException: org.postgresql.example.ComplexScalar (JNICalls.c:70)",,,,,,"COPY javatest.complextest (x) TO stdout;",0,,"/data/home/build/builds/greenplum-db/Release-4_2_0_0-build-3_rc_111211-1126/Release-4_2_0_0-build-3_src/cdb-pg/src/pl/pljava/src/C/pljava/JNICalls.c",70,"Stack trace:
    1 0xa7494e postgres errstart + 0x4ee
    2 0x7faa24938945 pljava.so <symbol not found> + 0x24938945
    3 0x7faa24938ef9 pljava.so JNI_callObjectMethodV + 0x69
    4 0x7faa249392ed pljava.so JNI_callObjectMethod + 0x9d
    5 0x7faa24934b20 pljava.so Function_getFunction + 0x780
    6 0x7faa249306d8 pljava.so <symbol not found> + 0x249306d8
    7 0xa77f30 postgres FunctionCall1 + 0x50
    8 0xa77fac postgres OutputFunctionCall + 0x2c
    9 0x64aac5 postgres CopyOneRowTo + 0x215
    10 0x64ef1a postgres <symbol not found> + 0x64ef1a
    11 0x65de89 postgres DoCopy + 0xb89
    12 0x91a264 postgres ProcessUtility + 0x914
    13 0x917a30 postgres PortalRun + 0xa00
    14 0x90d289 postgres <symbol not found> + 0x90d289
    15 0x910cdc postgres PostgresMain + 0xe8c
    16 0x878265 postgres <symbol not found> + 0x878265
    17 0x87f2d0 postgres PostmasterMain + 0x12f0
    18 0x78364a postgres main + 0x4da
    19 0x7faa3d5a4cdd libc.so.6 __libc_start_main + 0xfd
    20 0x47d2a9 postgres <symbol not found> + 0x47d2a9

    #######################################
    prqa=# select * from javatest.complextest;
    ERROR: java.sql.SQLException: IOException reading jar: /usr/local/GP-4.2.8.1/lib/postgresql/java/PR_gfRouter-1.1.2.jar (Permission denied) (JNICalls.c:70)
    prqa=# set pljava_classpath='examples.jar';
    SET
    prqa=# select * from javatest.complextest ;

    x

    (1.0,2.0)
    (1 row)
    #######################################

Powered by Zendesk