Exception while testing a routine call

167 views
Skip to first unread message

giandin...@gmail.com

unread,
Mar 24, 2015, 1:34:55 PM3/24/15
to jooq...@googlegroups.com

Good afternoon all,

I have generated jOOQ classes for database objects in a Oracle 11g database: the generation was successful.

One of the database objects is a PL/SQL procedure with the following signature:

PROCEDURE search_public

( i_comref_id           IN      VARCHAR2                 
  ,i_free_text           IN      VARCHAR2
  ,i_is_manager          IN      VARCHAR2 
  ,i_current_user_login  IN      t$users.user_login%TYPE
  ,o_ref_list               OUT  setup$m.CUSTOM_REF_CURSOR
  ,i_orderby             IN      VARCHAR2
  ,i_order               IN      VARCHAR2
  ,o_result                 OUT  VARCHAR2)

My jUnit test of the corresponding class SearchPublic() fails with the following stacktrace:

java.lang.NullPointerException
 at org.jooq.impl.DefaultDataType.getSQLType(DefaultDataType.java:510)
 at org.jooq.impl.DefaultBinding.register(DefaultBinding.java:766)
 at org.jooq.impl.AbstractRoutine.registerOutParameter(AbstractRoutine.java:622)
 at org.jooq.impl.AbstractRoutine.registerOutParameters(AbstractRoutine.java:616)
 at org.jooq.impl.AbstractRoutine.executeCallableStatement(AbstractRoutine.java:339)
 at org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:270)
 at org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:256)

The problems seem to originate in the instantiation
SearchPublic searchPublic = new SearchPublic();
and are described as follows by IntelliJ:
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate domain.framew.packages.user$o.SearchPublic.toString()

Do you know what might be going wrong?

Thank you, kind regards,

Lukas Eder

unread,
Mar 24, 2015, 6:56:30 PM3/24/15
to jooq...@googlegroups.com
Hmm, interesting. This is clearly a bug - either in the code generator, or in the way jOOQ handles the CUSTOM_REF_CURSOR type at runtime.
Can you provide us with the PL/SQL declaration of setup$m, including setup$m.CUSTOM_REF_CURSOR?

Best Regards,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

giandin...@gmail.com

unread,
Mar 25, 2015, 4:10:10 AM3/25/15
to jooq...@googlegroups.com
Good morning Lukas,
 
Please see in attachment the setup$m.pks file containing the declaration and definition fo the cursor.
 
Thank you, kind regards,
setup$m.pks

Lukas Eder

unread,
Mar 25, 2015, 9:03:54 AM3/25/15
to jooq...@googlegroups.com
Hi Gian,

Interesting. I've now tried the following piece of PL/SQL code, which resembles what you did:

CREATE OR REPLACE PACKAGE setup$m AS
TYPE CUSTOM_REF_CURSOR IS REF CURSOR;
PROCEDURE search_public
( i_comref_id           IN      VARCHAR2                  
  ,i_free_text           IN      VARCHAR2
  ,i_is_manager          IN      VARCHAR2  
  ,i_current_user_login  IN      VARCHAR2
  ,o_ref_list               OUT  setup$m.CUSTOM_REF_CURSOR
  ,i_orderby             IN      VARCHAR2
  ,i_order               IN      VARCHAR2
  ,o_result                 OUT  VARCHAR2);
END setup$m;
/

CREATE OR REPLACE PACKAGE BODY setup$m AS
PROCEDURE search_public
( i_comref_id           IN      VARCHAR2                  
  ,i_free_text           IN      VARCHAR2
  ,i_is_manager          IN      VARCHAR2  
  ,i_current_user_login  IN      VARCHAR2
  ,o_ref_list               OUT  setup$m.CUSTOM_REF_CURSOR
  ,i_orderby             IN      VARCHAR2
  ,i_order               IN      VARCHAR2
  ,o_result                 OUT  VARCHAR2) IS
BEGIN
  OPEN o_ref_list FOR SELECT 1 a FROM DUAL;
END search_public;
END setup$m;
/

I then called the above procedure like this, without any issues:

SearchPublic result = Setup$m.searchPublic(configuration, null, null, null, null, null, null);
System.out.println(result.getORefList());

The output I got was:

+----+
|   A|
+----+
|   1|
+----+

I've reviewed the exception that you've posted:

java.lang.NullPointerException
 at org.jooq.impl.DefaultDataType.getSQLType(DefaultDataType.java:510)
 at org.jooq.impl.DefaultBinding.register(DefaultBinding.java:766)
 at org.jooq.impl.AbstractRoutine.registerOutParameter(AbstractRoutine.java:622)
 at org.jooq.impl.AbstractRoutine.registerOutParameters(AbstractRoutine.java:616)
 at org.jooq.impl.AbstractRoutine.executeCallableStatement(AbstractRoutine.java:339)
 at org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:270)
 at org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:256)

It points to the following line of code:

        else if (Result.class.isAssignableFrom(type)) {
            switch (dialect.family()) {
                /* [pro] */
                case ORACLE:
                /* [/pro] */
                case H2:
                    return -10; // OracleTypes.CURSOR;

                case POSTGRES:
                default:
                    return Types.OTHER;
            }
        }

But I don't see any way how this dialect could be null, normally... How did you create the configuration object you're using to call the stored procedure?

Another possible source of error: The jOOQ Open Source Edition is distributed to Maven Central and it doesn't contain the SQLDialect.ORACLE. Perhaps, your tests somehow pulled in the Open Source Edition runtime, instead of the trial / commercial edition? Could that be possible?

Best Regards,
Lukas

giandin...@gmail.com

unread,
Mar 25, 2015, 9:15:27 AM3/25/15
to jooq...@googlegroups.com
Hi Lukas,
 
Thank you for having a look.
 
As a rudimentary first test, with the configuration object, I wrote the following:
 
public void testSearchPublic() {
try {
DSLContext context = getDslContext();


SearchPublic searchPublic = new SearchPublic();

        searchPublic.setIComrefId("");
searchPublic.setIFreeText("");
searchPublic.setIIsManager("");
searchPublic.setICurrentUserLogin("");
searchPublic.setIOrderby("");
searchPublic.setIOrder("");

searchPublic.execute(context.configuration());

Result<Record> oRefList = searchPublic.getORefList();
String oResult = searchPublic.getOResult();

} catch (Exception e) {
e.printStackTrace();
}
}
 
The jOOQ edition has been downloaded from the web site and not obtained through Maven Central.
At run time it mentions '...the 30 day free jOOQ 3.5.3 trial edition'.
 
Kind regards,
 
Gian

Lukas Eder

unread,
Mar 26, 2015, 4:03:36 AM3/26/15
to jooq...@googlegroups.com
Hi Gian,

That is an alternative way to call the stored procedure. I've tried it as well and it works just fine for me. Perhaps the issue is related to how you produce that DSLContext instance in getDslContext()...?

Best Regards,
Lukas

Gian

unread,
Mar 26, 2015, 4:13:10 AM3/26/15
to jooq...@googlegroups.com
Good morning Lukas,
 
I create the DSLContext in the method as follows:
 
private DSLContext getDslContext() throws SQLException {
Connection conn = DriverManager.getConnection(url, userName, password);
return DSL.using(conn, SQLDialect.ORACLE11G);
}
 
In the mean time I'm stepping in through the breakpoints as we speak ;-)
 
Thank you, kind regards,
 
Gian

Gian

unread,
Mar 26, 2015, 5:15:29 AM3/26/15
to jooq...@googlegroups.com
Hello Lukas,
 
Maybe the following might give an indication...
 
At a certain point the code lands in the following class DefaultDataType and more specifically in...
 
if (dialect != null) {
    result = TYPES_BY_TYPE[dialect.ordinal()].get(type);
}
in this snippet the result evaluates to null
dialect.ordinal() evaluates to 20
dialect evaluates to ORACLE11G
type evaluates to org.jooq.Result.class
 
Best regards,

Lukas Eder

unread,
Mar 27, 2015, 3:39:58 AM3/27/15
to jooq...@googlegroups.com
Hi Gian,

Thank you very much for this bit of information. That's it, I can reproduce the issue when passing from SQLDialect.ORACLE (what I had used) to SQLDialect.ORACLE11G. I've created an issue for this, which we'll fix ASAP:

As a workaround, for the time being, you could probably switch your dialect to ORACLE instead of ORACLE11G. For instance, we haven't switched the LIMIT .. OFFSET emulation to Oracle 12c's OFFSET .. FETCH yet, and our integration tests with SQLDialect.ORACLE still run smoothly on Oracle 11g.

Thanks for your very useful help in this case. This has been a bit tricky to debug. I'll keep you posted on progress of fixing #4156

Best Regards,
Lukas


Gian

unread,
Mar 27, 2015, 8:38:39 AM3/27/15
to jooq...@googlegroups.com
Good afternoon Lukas,
 
Thank you for picking that up.
 
In the mean time I've just tried with the adapted dialect and my first
procedure call and (rudimentary) iteration over the results works, I'm
happy ;-)
 
Best regards,
 
Gian

Lukas Eder

unread,
Mar 27, 2015, 2:01:05 PM3/27/15
to jooq...@googlegroups.com
Thanks for the feedback. I'm glad to hear it worked for you, with the version-independent dialect.

In the meantime, this issue was fixed on GitHub master:

Thanks again for reporting this issue!

Best Regards,
Lukas
Reply all
Reply to author
Forward
0 new messages