From 90631eff600ad09c7e46b3100e0e33e138871192 Mon Sep 17 00:00:00 2001
From: Danny Plenge <dannyplenge@gmail.com>
Date: Tue, 20 Mar 2018 16:10:09 +0100
Subject: [PATCH] Removed dangerous instance of double-checked locking in
 ThemePluginImpl

---
 .../mage/plugins/theme/ThemePluginImpl.java   | 68 +++++++++----------
 1 file changed, 32 insertions(+), 36 deletions(-)

diff --git a/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java
index 43c788e983..6f9b00879f 100644
--- a/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java
+++ b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java
@@ -150,47 +150,43 @@ public class ThemePluginImpl implements ThemePlugin {
         return bgPanel;
     }
 
-    private ImagePanel createImagePanelInstance() {
+    private synchronized ImagePanel createImagePanelInstance() {
         if (background == null) {
-            synchronized (ThemePluginImpl.class) {
-                if (background == null) {
-                    String filename = "/background.png";
-                    try {
-                        if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")) {
-                            InputStream is = this.getClass().getResourceAsStream(filename);
-                            if (is == null) {
-                                throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
-                            }
-                            background = ImageIO.read(is);
-                        } else {
-                            String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, "");
-                            if (path != null && !path.isEmpty()) {
-                                try {
-                                    File f = new File(path);
-                                    if (f != null) {
-                                        background = ImageIO.read(f);
-                                    }
-                                } catch (Exception e) {
-                                    background = null;
-                                }
-                            }
-                        }
-                        if (background == null) {
-                            InputStream is = this.getClass().getResourceAsStream(filename);
-                            if (is == null) {
-                                throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
-                            }
-                            background = ImageIO.read(is);
-                        }
-                        if (background == null) {
+                String filename = "/background.png";
+                try {
+                    if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")) {
+                        InputStream is = this.getClass().getResourceAsStream(filename);
+                        if (is == null) {
                             throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
                         }
-                    } catch (Exception e) {
-                        log.error(e.getMessage(), e);
-                        return null;
+                        background = ImageIO.read(is);
+                    } else {
+                        String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, "");
+                        if (path != null && !path.isEmpty()) {
+                            try {
+                                File f = new File(path);
+                                if (f != null) {
+                                    background = ImageIO.read(f);
+                                }
+                            } catch (Exception e) {
+                                background = null;
+                            }
+                        }
                     }
+                    if (background == null) {
+                        InputStream is = this.getClass().getResourceAsStream(filename);
+                        if (is == null) {
+                            throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
+                        }
+                        background = ImageIO.read(is);
+                    }
+                    if (background == null) {
+                        throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
+                    }
+                } catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                    return null;
                 }
-            }
         }
         return new ImagePanel(background, ImagePanelStyle.SCALED);
     }