@@ -63,16 +63,16 @@ public static EntitlementChecker checker() {
6363 public static void initialize (Instrumentation inst ) throws Exception {
6464 manager = initChecker ();
6565
66+ var latestCheckerInterface = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
67+ EntitlementChecker .class ,
68+ Runtime .version ().feature ()
69+ );
6670 var verifyBytecode = Booleans .parseBoolean (System .getProperty ("es.entitlements.verify_bytecode" , "false" ));
6771 if (verifyBytecode ) {
6872 ensureClassesSensitiveToVerificationAreInitialized ();
6973 }
7074
71- DynamicInstrumentation .initialize (
72- inst ,
73- getVersionSpecificCheckerClass (EntitlementChecker .class , Runtime .version ().feature ()),
74- verifyBytecode
75- );
75+ DynamicInstrumentation .initialize (inst , latestCheckerInterface , verifyBytecode );
7676 }
7777
7878 private static PolicyManager createPolicyManager () {
@@ -116,41 +116,13 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
116116 }
117117 }
118118
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-
150119 private static ElasticsearchEntitlementChecker initChecker () {
151120 final PolicyManager policyManager = createPolicyManager ();
152121
153- final Class <?> clazz = getVersionSpecificCheckerClass (ElasticsearchEntitlementChecker .class , Runtime .version ().feature ());
122+ final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
123+ ElasticsearchEntitlementChecker .class ,
124+ Runtime .version ().feature ()
125+ );
154126
155127 Constructor <?> constructor ;
156128 try {
0 commit comments