@@ -63,16 +63,16 @@ public static EntitlementChecker checker() {
63
63
public static void initialize (Instrumentation inst ) throws Exception {
64
64
manager = initChecker ();
65
65
66
+ var latestCheckerInterface = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
67
+ EntitlementChecker .class ,
68
+ Runtime .version ().feature ()
69
+ );
66
70
var verifyBytecode = Booleans .parseBoolean (System .getProperty ("es.entitlements.verify_bytecode" , "false" ));
67
71
if (verifyBytecode ) {
68
72
ensureClassesSensitiveToVerificationAreInitialized ();
69
73
}
70
74
71
- DynamicInstrumentation .initialize (
72
- inst ,
73
- getVersionSpecificCheckerClass (EntitlementChecker .class , Runtime .version ().feature ()),
74
- verifyBytecode
75
- );
75
+ DynamicInstrumentation .initialize (inst , latestCheckerInterface , verifyBytecode );
76
76
}
77
77
78
78
private static PolicyManager createPolicyManager () {
@@ -116,41 +116,13 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
116
116
}
117
117
}
118
118
119
- /**
120
- * Returns the "most recent" checker class compatible with the current runtime Java version.
121
- * For checkers, we have (optionally) version specific classes, each with a prefix (e.g. Java23).
122
- * The mapping cannot be automatic, as it depends on the actual presence of these classes in the final Jar (see
123
- * the various mainXX source sets).
124
- */
125
- static Class <?> getVersionSpecificCheckerClass (Class <?> baseClass , int javaVersion ) {
126
- String packageName = baseClass .getPackageName ();
127
- String baseClassName = baseClass .getSimpleName ();
128
-
129
- final String classNamePrefix ;
130
- if (javaVersion < 19 ) {
131
- // For older Java versions, the basic EntitlementChecker interface and implementation contains all the supported checks
132
- classNamePrefix = "" ;
133
- } else if (javaVersion < 23 ) {
134
- classNamePrefix = "Java" + javaVersion ;
135
- } else {
136
- // All Java version from 23 onwards will be able to use che checks in the Java23EntitlementChecker interface and implementation
137
- classNamePrefix = "Java23" ;
138
- }
139
-
140
- final String className = packageName + "." + classNamePrefix + baseClassName ;
141
- Class <?> clazz ;
142
- try {
143
- clazz = Class .forName (className );
144
- } catch (ClassNotFoundException e ) {
145
- throw new AssertionError ("entitlement lib cannot find entitlement class " + className , e );
146
- }
147
- return clazz ;
148
- }
149
-
150
119
private static ElasticsearchEntitlementChecker initChecker () {
151
120
final PolicyManager policyManager = createPolicyManager ();
152
121
153
- final Class <?> clazz = getVersionSpecificCheckerClass (ElasticsearchEntitlementChecker .class , Runtime .version ().feature ());
122
+ final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
123
+ ElasticsearchEntitlementChecker .class ,
124
+ Runtime .version ().feature ()
125
+ );
154
126
155
127
Constructor <?> constructor ;
156
128
try {
0 commit comments