mirror of
https://github.com/apache/struts.git
synced 2026-08-07 23:57:03 +00:00
WW-3689 Adds synchronized block with global lock to avoid NPE
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1485576 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+6
-7
@@ -21,22 +21,21 @@
|
||||
|
||||
package org.apache.struts2.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Context;
|
||||
import com.opensymphony.xwork2.inject.Factory;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class LegacyPropertiesConfigurationProvider implements ConfigurationProvider {
|
||||
|
||||
/**
|
||||
@@ -69,10 +68,10 @@ public class LegacyPropertiesConfigurationProvider implements ConfigurationProvi
|
||||
loadSettings(props, settings);
|
||||
|
||||
// Set default locale by lazily resolving the locale property as needed into a Locale object
|
||||
builder.factory(Locale.class, new Factory() {
|
||||
builder.factory(Locale.class, new Factory<Locale>() {
|
||||
private Locale locale;
|
||||
|
||||
public synchronized Object create(Context context) throws Exception {
|
||||
public synchronized Locale create(Context context) throws Exception {
|
||||
if (locale == null) {
|
||||
String loc = context.getContainer().getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
|
||||
if (loc != null) {
|
||||
|
||||
@@ -21,16 +21,14 @@
|
||||
|
||||
package org.apache.struts2.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,6 +72,11 @@ class Settings {
|
||||
*/
|
||||
static Settings defaultImpl;
|
||||
|
||||
/**
|
||||
* Guard used to protect the defaultImpl initialisation.
|
||||
*/
|
||||
private static final Object DEFAULT_LOCK = new Object();
|
||||
|
||||
/**
|
||||
* An instance of the default locale as specified by the <code>struts.locale</code> setting.
|
||||
*
|
||||
@@ -267,23 +270,27 @@ class Settings {
|
||||
*/
|
||||
private static Settings getDefaultInstance() {
|
||||
if (defaultImpl == null) {
|
||||
// Create bootstrap implementation
|
||||
defaultImpl = new DefaultSettings();
|
||||
synchronized (DEFAULT_LOCK) {
|
||||
if (defaultImpl == null) {
|
||||
// Create bootstrap implementation
|
||||
defaultImpl = new DefaultSettings();
|
||||
|
||||
// Create default implementation
|
||||
try {
|
||||
String className = get(StrutsConstants.STRUTS_CONFIGURATION);
|
||||
|
||||
if (!className.equals(defaultImpl.getClass().getName())) {
|
||||
// Create default implementation
|
||||
try {
|
||||
// singleton instances shouldn't be built accessing request or session-specific context data
|
||||
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Settings: Could not instantiate the struts.configuration object, substituting the default implementation.", e);
|
||||
String className = get(StrutsConstants.STRUTS_CONFIGURATION);
|
||||
|
||||
if (!className.equals(defaultImpl.getClass().getName())) {
|
||||
try {
|
||||
// singleton instances shouldn't be built accessing request or session-specific context data
|
||||
defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Settings: Could not instantiate the struts.configuration object, substituting the default implementation.", e);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +301,10 @@ class Settings {
|
||||
* Resets the default and any plugin Setting instance to null.
|
||||
*/
|
||||
public static void reset() {
|
||||
defaultImpl = null;
|
||||
synchronized (DEFAULT_LOCK) {
|
||||
defaultImpl = null;
|
||||
}
|
||||
settingsImpl = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user