fix: avoid reflective access to TimeZone.defaultTimeZone in Java 9+ #1002
Conversation
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) { |
jorsol
Oct 31, 2017
Member
it should be chatAt(2) >= '6'
and you forgot the quotes for '8'
.
it should be chatAt(2) >= '6'
and you forgot the quotes for '8'
.
vlsi
Oct 31, 2017
Author
Member
Thanks, makes sense
Thanks, makes sense
Object tzFromField = tzField.get(null); | ||
if (defaultTz == null || !defaultTz.equals(tzFromField)) { | ||
tzField = null; | ||
String javaVersion = System.getProperty("java.version"); |
jorsol
Oct 31, 2017
Member
I think the Java version check must be in an utility method.
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
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