-
Notifications
You must be signed in to change notification settings - Fork 845
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
fix: avoid reflective access to TimeZone.defaultTimeZone in Java 9+ #1002
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not better to use the preprocessor to do the version check?
tzField = null; | ||
// Avoid reflective access in Java 9+ | ||
if (javaVersion.startsWith("1.") && javaVersion.length() == 3 | ||
&& javaVersion.charAt(2) >= '4' && javaVersion.charAt(2) <= 8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be chatAt(2) >= '6'
and you forgot the quotes for '8'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, makes sense
Object tzFromField = tzField.get(null); | ||
if (defaultTz == null || !defaultTz.equals(tzFromField)) { | ||
tzField = null; | ||
String javaVersion = System.getProperty("java.version"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Java version check must be in an utility method.
preprocessor is compile-time thing, while the point is to check JRE at runtime. |
Codecov Report
@@ Coverage Diff @@
## master #1002 +/- ##
============================================
+ Coverage 65.71% 65.87% +0.15%
+ Complexity 3604 3579 -25
============================================
Files 168 167 -1
Lines 15491 15320 -171
Branches 2494 2482 -12
============================================
- Hits 10180 10092 -88
+ Misses 4134 4050 -84
- Partials 1177 1178 +1 |
1910c8a
to
8bb2477
Compare
No idea if this was the latest solution, but I'm getting the same warning on Java 11:
What does the committed code do with a Java version String of "11.0.3"? I found a commit with this: tzField = null;
// Avoid reflective access in Java 9+
if (JavaVersion.getRuntimeVersion().compareTo(JavaVersion.v1_8) <= 0) {
tzField = TimeZone.class.getDeclaredField("defaultTimeZone");
tzField.setAccessible(true); How does this work? Does the |
Good question. |
@jugimaster what version of the driver are you using? |
org.postgresql/postgresql "9.4.1212" (It's a Clojure project.) |
upgrade the driver to the latest. |
Oh, alright. I just assumed it wouldn't be older than something from 2017 |
closes #986