@@ -70,7 +70,7 @@ public static void initialize(Instrumentation inst) throws Exception {
70
70
71
71
DynamicInstrumentation .initialize (
72
72
inst ,
73
- EntitlementCheckerUtils . getVersionSpecificCheckerClass (EntitlementChecker .class , Runtime .version ().feature ()),
73
+ getVersionSpecificCheckerClass (EntitlementChecker .class , Runtime .version ().feature ()),
74
74
verifyBytecode
75
75
);
76
76
}
@@ -88,9 +88,7 @@ private static PolicyManager createPolicyManager() {
88
88
pluginPolicies ,
89
89
EntitlementBootstrap .bootstrapArgs ().scopeResolver (),
90
90
EntitlementBootstrap .bootstrapArgs ().sourcePaths (),
91
- ENTITLEMENTS_MODULE ,
92
- pathLookup ,
93
- bootstrapArgs .suppressFailureLogClasses ()
91
+ pathLookup
94
92
);
95
93
}
96
94
@@ -115,10 +113,7 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
115
113
private static ElasticsearchEntitlementChecker initChecker () {
116
114
final PolicyManager policyManager = createPolicyManager ();
117
115
118
- final Class <?> clazz = EntitlementCheckerUtils .getVersionSpecificCheckerClass (
119
- ElasticsearchEntitlementChecker .class ,
120
- Runtime .version ().feature ()
121
- );
116
+ final Class <?> clazz = getVersionSpecificCheckerClass (ElasticsearchEntitlementChecker .class , Runtime .version ().feature ());
122
117
123
118
Constructor <?> constructor ;
124
119
try {
@@ -132,4 +127,32 @@ private static ElasticsearchEntitlementChecker initChecker() {
132
127
throw new AssertionError (e );
133
128
}
134
129
}
130
+
131
+ /**
132
+ * Returns the "most recent" checker class compatible with the provided runtime Java version.
133
+ * For checkers, we have (optionally) version specific classes, each with a prefix (e.g. Java23).
134
+ * The mapping cannot be automatic, as it depends on the actual presence of these classes in the final Jar (see
135
+ * the various mainXX source sets).
136
+ */
137
+ static Class <?> getVersionSpecificCheckerClass (Class <?> baseClass , int javaVersion ) {
138
+ String packageName = baseClass .getPackageName ();
139
+ String baseClassName = baseClass .getSimpleName ();
140
+
141
+ final String classNamePrefix ;
142
+ if (javaVersion >= 23 ) {
143
+ // All Java version from 23 onwards will be able to use che checks in the Java23EntitlementChecker interface and implementation
144
+ classNamePrefix = "Java23" ;
145
+ } else {
146
+ // For any other Java version, the basic EntitlementChecker interface and implementation contains all the supported checks
147
+ classNamePrefix = "" ;
148
+ }
149
+ final String className = packageName + "." + classNamePrefix + baseClassName ;
150
+ Class <?> clazz ;
151
+ try {
152
+ clazz = Class .forName (className );
153
+ } catch (ClassNotFoundException e ) {
154
+ throw new AssertionError ("entitlement lib cannot find entitlement class " + className , e );
155
+ }
156
+ return clazz ;
157
+ }
135
158
}
0 commit comments