Skip to content

Commit 7ca09df

Browse files
author
Claude4.0s
committed
Updated for 4.57.0
1 parent 67526b6 commit 7ca09df

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss.SSSZ</maven.build.timestamp.format>
2727
<!-- remove source encoding warnings from maven output -->
2828
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29-
<version.java-util>3.6.0</version.java-util>
29+
<version.java-util>3.7.0</version.java-util>
3030
<!-- testing only -->
3131
<version.junit-jupiter-api>5.11.4</version.junit-jupiter-api>
3232
<version.junit-jupiter-params>5.11.4</version.junit-jupiter-params>

src/main/java/com/cedarsoftware/io/reflect/Injector.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import java.lang.reflect.Type;
1111
import java.util.Arrays;
1212

13-
import com.cedarsoftware.util.ReflectionUtils;
14-
1513
import com.cedarsoftware.io.JsonIoException;
16-
import com.cedarsoftware.util.ArrayUtilities;
17-
import com.cedarsoftware.util.CollectionUtilities;
1814
import com.cedarsoftware.util.Converter;
15+
import com.cedarsoftware.util.ReflectionUtils;
1916
import com.cedarsoftware.util.StringUtilities;
2017

2118
/**
@@ -66,7 +63,7 @@ public class Injector {
6663
private static final Class<?> VAR_HANDLE_CLASS; // although appears unused, it is intentional for caching
6764

6865
static {
69-
int javaVersion = getJavaVersion();
66+
int javaVersion = determineJdkMajorVersion();
7067
IS_JDK17_OR_HIGHER = javaVersion >= 17;
7168

7269
Object lookup = null;
@@ -408,21 +405,32 @@ public String getUniqueFieldName() {
408405
return uniqueFieldName;
409406
}
410407

411-
/**
412-
* Determines the Java major version by parsing the {@code java.version} system property.
413-
* This method handles both legacy (1.8) and modern (9+) version numbering schemes.
414-
*
415-
* @return the major Java version (e.g., 8 for Java 1.8, 17 for Java 17, etc.)
416-
*/
417-
private static int getJavaVersion() {
418-
String version = System.getProperty("java.version");
419-
if (version.startsWith("1.")) {
420-
return Integer.parseInt(version.substring(2, 3));
421-
}
422-
int dot = version.indexOf('.');
423-
if (dot != -1) {
424-
return Integer.parseInt(version.substring(0, dot));
408+
//TODO: remove and wire to java-util API for this (3.8.0+)
409+
private static int determineJdkMajorVersion() {
410+
try {
411+
Method versionMethod = ReflectionUtils.getMethod(Runtime.class, "version");
412+
Object v = versionMethod.invoke(Runtime.getRuntime());
413+
Method major = ReflectionUtils.getMethod(v.getClass(), "major");
414+
return (Integer) major.invoke(v);
415+
} catch (Exception ignore) {
416+
try {
417+
String version = System.getProperty("java.version");
418+
if (version.startsWith("1.")) {
419+
return Integer.parseInt(version.substring(2, 3));
420+
}
421+
int dot = version.indexOf('.');
422+
if (dot != -1) {
423+
return Integer.parseInt(version.substring(0, dot));
424+
}
425+
return Integer.parseInt(version);
426+
} catch (Exception ignored) {
427+
try {
428+
String spec = System.getProperty("java.specification.version");
429+
return spec.startsWith("1.") ? Integer.parseInt(spec.substring(2)) : Integer.parseInt(spec);
430+
} catch (NumberFormatException e) {
431+
return -1;
432+
}
433+
}
425434
}
426-
return Integer.parseInt(version);
427435
}
428436
}

src/test/java/com/cedarsoftware/io/reflect/InjectorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cedarsoftware.io.reflect;
22

33
import com.cedarsoftware.io.JsonIoException;
4+
import com.cedarsoftware.util.SystemUtilities;
45
import org.junit.jupiter.api.Test;
56

67
import java.lang.reflect.Field;

0 commit comments

Comments
 (0)