@@ -395,19 +395,31 @@ public static Source newSource(PythonContext ctxt, String src, String name) {
395
395
private final ConcurrentHashMap <Object , Source > cachedSources = new ConcurrentHashMap <>();
396
396
397
397
public Source newSource (PythonContext ctxt , TruffleFile src , String name ) throws IOException {
398
- Source source = cachedSources .get (src );
399
- if (source == null ) {
400
- cachedSources .put (src , source = newSource (ctxt , Source .newBuilder (ID , src ), name ));
398
+ try {
399
+ return cachedSources .computeIfAbsent (src , t -> {
400
+ try {
401
+ return newSource (ctxt , Source .newBuilder (ID , src ), name );
402
+ } catch (IOException e ) {
403
+ throw new RuntimeException (e );
404
+ }
405
+ });
406
+ } catch (RuntimeException e ) {
407
+ throw (IOException ) e .getCause ();
401
408
}
402
- return source ;
403
409
}
404
410
405
411
public Source newSource (PythonContext ctxt , URL url , String name ) throws IOException {
406
- Source source = cachedSources .get (url );
407
- if (source == null ) {
408
- cachedSources .put (url , source = newSource (ctxt , Source .newBuilder (ID , url ), name ));
412
+ try {
413
+ return cachedSources .computeIfAbsent (url , t -> {
414
+ try {
415
+ return newSource (ctxt , Source .newBuilder (ID , url ), name );
416
+ } catch (IOException e ) {
417
+ throw new RuntimeException (e );
418
+ }
419
+ });
420
+ } catch (RuntimeException e ) {
421
+ throw (IOException ) e .getCause ();
409
422
}
410
- return source ;
411
423
}
412
424
413
425
private static Source newSource (PythonContext ctxt , SourceBuilder srcBuilder , String name ) throws IOException {
0 commit comments