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

initializes com.mysql.jdbc.TimeUtil.timeZoneMappings if needed (Connector/J 5.x) #259

Merged
merged 3 commits into from
Aug 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected MySQLInputConnection newConnection(PluginTask task) throws SQLExceptio
logConnectionProperties(url, props);

// load timezone mappings
loadTimeZoneMappings();
loadTimeZoneMappingsIfNeeded();

Connection con = DriverManager.getConnection(url, props);
try {
Expand All @@ -145,7 +145,7 @@ protected ColumnGetterFactory newColumnGetterFactory(final PageBuilder pageBuild
return new MySQLColumnGetterFactory(pageBuilder, dateTimeZone);
}

private void loadTimeZoneMappings()
private void loadTimeZoneMappingsIfNeeded()
{
// Here initializes com.mysql.jdbc.TimeUtil.timeZoneMappings static field by calling
// static timeZoneMappings method using reflection.
Expand All @@ -156,7 +156,10 @@ private void loadTimeZoneMappings()
// from the classloader. It seems like a bug of JDBC Driver where it should use the class loader
// that loaded com.mysql.jdbc.TimeUtil class rather than system class loader to read the
// property file because the file should be in the same classpath with the class.
// Here implements a workaround as as workaround.
// Here implements a workaround as a workaround.
//
// It's not 100% sure, but this workaround is necessary for Connector/J 5.x (com.mysql.jdbc.TimeUtil)
// only.
hiroyuki-sato marked this conversation as resolved.
Show resolved Hide resolved
Field f = null;
try {
Class<?> timeUtilClass = Class.forName("com.mysql.jdbc.TimeUtil");
Expand All @@ -172,7 +175,11 @@ private void loadTimeZoneMappings()
f.set(null, timeZoneMappings);
}
}
catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | IOException e) {
catch (ClassNotFoundException e) {
// It appears that the user uses the Connector/J 8.x driver.
// Do nothing;
hiroyuki-sato marked this conversation as resolved.
Show resolved Hide resolved
}
catch (IllegalAccessException | NoSuchFieldException | IOException e) {
throw new RuntimeException(e);
}
finally {
Expand Down