Skip to content

Commit

Permalink
Change PropertyUtil to use system class loader as fallback
Browse files Browse the repository at this point in the history
This is an attempt to fix NPE/ParseExceptions thrown on init due to iqfeed4j.default.properties not existing on the system class loader's classpath.
  • Loading branch information
Petersoj committed Oct 28, 2021
1 parent d59f0a0 commit 43d31d4
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
public class PropertyUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(PropertyUtil.class);
private static final Map<String, Properties> CACHED_PROPERTIES = Collections.synchronizedMap(new HashMap<>());

public static final Map<String, Properties> CACHED_PROPERTIES = Collections.synchronizedMap(new HashMap<>());

/**
* Gets a string property from a property file. Will try to IO load the properties in the property file if not
Expand Down Expand Up @@ -80,11 +81,14 @@ public static String getProperty(String propertyFile, String defaultPropertyFile
* @return the properties
*/
public synchronized static Properties loadPropertyFile(String propertyFile, String defaultPropertyFile) {
Properties properties = null;
ClassLoader classLoader = PropertyUtil.class.getClassLoader();
if (classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
}

// Load the default property file if exists
Properties defaultProperties = null;
InputStream defaultPropertyStream = ClassLoader.getSystemClassLoader().getResourceAsStream(defaultPropertyFile);
InputStream defaultPropertyStream = classLoader.getResourceAsStream(defaultPropertyFile);

if (defaultPropertyStream != null) {
defaultProperties = new Properties();
Expand All @@ -109,7 +113,8 @@ public synchronized static Properties loadPropertyFile(String propertyFile, Stri
}

// Load the property file
InputStream propertyStream = ClassLoader.getSystemClassLoader().getResourceAsStream(propertyFile);
Properties properties = null;
InputStream propertyStream = classLoader.getResourceAsStream(propertyFile);

if (propertyStream != null) {
// Add default properties if they were found
Expand Down

0 comments on commit 43d31d4

Please sign in to comment.