Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print Java stacktrace at debug level #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

usimd
Copy link
Contributor

@usimd usimd commented Feb 21, 2023

If the JDBC driver throws an exception, it is helpful to print the stacktrace while debugging.

@Kenchir
Copy link

Kenchir commented Jun 6, 2023

LGTM

@@ -1275,6 +1275,52 @@ jq_exception_clear()
return;
}

/*
* Helper Method from JNIHelp.c from android source code
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you modify the comment for functions following the format below?

/*
 * function name: description about its functionality
 */

/*
* Helper Method from JNIHelp.c from android source code
*/
static jmethodID FindMethod(JNIEnv* env,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you naming the function following the naming rule? For example, jq_find_method

const char* className,
const char* methodName,
const char* descriptor) {
// This method is only valid for classes in the core library which are
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cover the comment using /* */

@@ -1300,12 +1348,43 @@ jq_get_exception()
{
ereport(ERROR, (errmsg("java/lang/Object class could not be created")));
}
// Stack Trace
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new function, for example jq_print_stack_trace(), to cover L1351 - L1381

{
jobject sw = NewStringWriter(Jenv);
if (sw == NULL) {
ereport(ERROR, (errmsg("String Writer is null")));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because our purpose is to print stack trace at debug level (DEBUG3), so I think this error should only be displayed if DEBUG3 level is set in postgresql.conf.

jobject pw = NewPrintWriter(Jenv, sw);
if (pw == NULL) {
(*Jenv)->DeleteLocalRef(Jenv, sw);
ereport(ERROR, (errmsg("Trace is null")));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message should be 'Print Writer is null'


jstring trace = StringWriterToString(Jenv, sw);
(*Jenv)->DeleteLocalRef(Jenv, pw);
pw = NULL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to set 'sw' and 'pw' to NULL.

ereport(ERROR, (errmsg("Trace is null!!!")));
}

exceptionStackTraceString = jdbc_convert_string_to_cstring((jobject) trace);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the ident in this line of code.

@jopoly
Copy link

jopoly commented Dec 21, 2023

could you add test case(s) to verify the added code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants