Extras: fixed concurrent loading of SVG icons on multiple threads (issue #459)

This commit is contained in:
Karl Tauber
2021-12-30 11:24:48 +01:00
parent bb32c727b6
commit 0cdfd29ecf
3 changed files with 36 additions and 3 deletions

View File

@@ -273,10 +273,12 @@ public class FlatSVGIcon
// since the input stream is already loaded and parsed,
// get diagram here and remove it from cache
update();
svgCache.remove( uri );
synchronized( FlatSVGIcon.class ) {
svgCache.remove( uri );
}
}
private static URI loadFromStream( InputStream in ) throws IOException {
private static synchronized URI loadFromStream( InputStream in ) throws IOException {
try( InputStream in2 = in ) {
return svgUniverse.loadSVG( in2, "/flatlaf-stream-" + (streamNumber++) );
}
@@ -475,7 +477,7 @@ public class FlatSVGIcon
loadFailed = (diagram == null);
}
static SVGDiagram loadSVG( URI uri ) {
static synchronized SVGDiagram loadSVG( URI uri ) {
// get from our cache
SVGDiagram diagram = svgCache.get( uri );
if( diagram != null )