@@ -68,7 +68,11 @@ public static void initialize(Instrumentation inst) throws Exception {
6868 ensureClassesSensitiveToVerificationAreInitialized ();
6969 }
7070
71- DynamicInstrumentation .initialize (inst , getVersionSpecificCheckerClass (EntitlementChecker .class ), verifyBytecode );
71+ DynamicInstrumentation .initialize (
72+ inst ,
73+ EntitlementCheckerUtils .getVersionSpecificCheckerClass (EntitlementChecker .class , Runtime .version ().feature ()),
74+ verifyBytecode
75+ );
7276 }
7377
7478 private static PolicyManager createPolicyManager () {
@@ -108,39 +112,13 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
108112 }
109113 }
110114
111- /**
112- * Returns the "most recent" checker class compatible with the current runtime Java version.
113- * For checkers, we have (optionally) version specific classes, each with a prefix (e.g. Java23).
114- * The mapping cannot be automatic, as it depends on the actual presence of these classes in the final Jar (see
115- * the various mainXX source sets).
116- */
117- private static Class <?> getVersionSpecificCheckerClass (Class <?> baseClass ) {
118- String packageName = baseClass .getPackageName ();
119- String baseClassName = baseClass .getSimpleName ();
120- int javaVersion = Runtime .version ().feature ();
121-
122- final String classNamePrefix ;
123- if (javaVersion >= 23 ) {
124- // All Java version from 23 onwards will be able to use che checks in the Java23EntitlementChecker interface and implementation
125- classNamePrefix = "Java23" ;
126- } else {
127- // For any other Java version, the basic EntitlementChecker interface and implementation contains all the supported checks
128- classNamePrefix = "" ;
129- }
130- final String className = packageName + "." + classNamePrefix + baseClassName ;
131- Class <?> clazz ;
132- try {
133- clazz = Class .forName (className );
134- } catch (ClassNotFoundException e ) {
135- throw new AssertionError ("entitlement lib cannot find entitlement class " + className , e );
136- }
137- return clazz ;
138- }
139-
140115 private static ElasticsearchEntitlementChecker initChecker () {
141116 final PolicyManager policyManager = createPolicyManager ();
142117
143- final Class <?> clazz = getVersionSpecificCheckerClass (ElasticsearchEntitlementChecker .class );
118+ final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
119+ ElasticsearchEntitlementChecker .class ,
120+ Runtime .version ().feature ()
121+ );
144122
145123 Constructor <?> constructor ;
146124 try {
0 commit comments