FirebirdSQL/fbjava

Error when calling java function inside default connection of other java function

artyom-smirnov opened this issue · 1 comments

Example:

public static int a() {
    return 123;
}

public static int b() throws SQLException {
    Connection con = DriverManager.getConnection("jdbc:default:connection:");
    PreparedStatement pstmt = con.prepareStatement("select a() from rdb$database");
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    return rs.getInt(1);
}
create function a() returns int external name 'a()' engine java;
create function b() returns int external name 'b()' engine java;
commit;

select b() from rdb$database;

Both functions share same InternalContext, so after closing context from first function, second fails with error:


           B 
============ 
Statement failed, SQLSTATE = HY000
java.lang.NullPointerException
	at org.firebirdsql.fbjava.impl.InternalContext.close(InternalContext.java:152)
	at org.firebirdsql.fbjava.impl.ExternalFunction.execute(ExternalFunction.java:74)
	at org.firebirdsql.fbjava.impl.FbClientLibrary$IExternalFunction$VTable$2.invoke(FbClientLibrary.java:9580)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:485)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:515)

-At function 'B'
After line 0 in file test.sql

@artyom-smirnov I did committed different fix after rework on contexts and security. Please test it if you can.