@@ -203,8 +203,8 @@ boolean requiresEagerUnpack() {
203
203
* the Truffle runtime is created and accessor classes are initialized. For this reason, it
204
204
* cannot use {@code EngineSupport} to call this method, nor can this method use any accessor.
205
205
*/
206
- static Path installRuntimeResource (InternalResource resource ) throws IOException {
207
- InternalResourceCache cache = createRuntimeResourceCache (resource );
206
+ static Path installRuntimeResource (InternalResource resource , String id ) throws IOException {
207
+ InternalResourceCache cache = createRuntimeResourceCache (resource , id );
208
208
synchronized (cache ) {
209
209
Path result = cache .path ;
210
210
if (result == null ) {
@@ -215,14 +215,21 @@ static Path installRuntimeResource(InternalResource resource) throws IOException
215
215
}
216
216
}
217
217
218
- private static InternalResourceCache createRuntimeResourceCache (InternalResource resource ) {
219
- InternalResource .Id id = resource .getClass ().getAnnotation (InternalResource .Id .class );
220
- assert id != null : resource .getClass () + " must be annotated by @InternalResource.Id" ;
221
- InternalResourceCache cache = new InternalResourceCache (PolyglotEngineImpl .ENGINE_ID , id .value (), () -> resource );
218
+ private static InternalResourceCache createRuntimeResourceCache (InternalResource resource , String id ) {
219
+ assert verifyAnnotationConsistency (resource , id ) : resource .getClass () + " must be annotated by @InternalResource.Id(\" " + id + "\" " ;
220
+ InternalResourceCache cache = new InternalResourceCache (PolyglotEngineImpl .ENGINE_ID , id , () -> resource );
222
221
InternalResourceRoots .initializeRuntimeResource (cache );
223
222
return cache ;
224
223
}
225
224
225
+ private static boolean verifyAnnotationConsistency (InternalResource resource , String expectedId ) {
226
+ InternalResource .Id id = resource .getClass ().getAnnotation (InternalResource .Id .class );
227
+ if (id == null ) {
228
+ return false ;
229
+ }
230
+ return id .value ().equals (expectedId );
231
+ }
232
+
226
233
private static InternalResource .Env createInternalResourceEnvReflectively (InternalResource resource ) {
227
234
try {
228
235
Constructor <InternalResource .Env > newEnv = InternalResource .Env .class .getDeclaredConstructor (InternalResource .class , BooleanSupplier .class );
0 commit comments