Removed dangerous instance of double-checked locking in ThemePluginImpl

This commit is contained in:
Danny Plenge 2018-03-20 16:10:09 +01:00
parent 3e1312064f
commit 90631eff60

View file

@ -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);
}