public static Properties prop;
private static UnionAuthProperties unionAuthProperties;
private UnionAuthProperties() {
try {
prop = PropertiesUtil.getPropertiesFromClassPath("unionauth.properties");
} catch (Exception e) {
LOG.error("{}",e);
}
}
public static synchronized UnionAuthProperties getInstance() {
if (unionAuthProperties == null) {
unionAuthProperties = new UnionAuthProperties(); #27
}
return unionAuthProperties;
}
private final String URL_REQUEST = prop.getProperty("url.request"); #32
The last statement URL_REQUEST causes:
threw exception
java.lang.NullPointerException
at UnionAuthProperties.<init>(UnionAuthProperties.java:32)
at UnionAuthProperties.getInstance(UnionAuthProperties.java:27)
at UnionAuthClient.<init>(UnionAuthClient.java:9)
based on my knowledge, instance no matter final or not are initiated after constructor [1] while the final ones have to be assigned before the end of constructor [2]. So why prop is NULL when URL_REQUEST is initialized?
EDIT: If right after super() and this(...) complete, instances are initialized, then the final instance REDIRECT_URI should be initialized to null or blank. However this prints REDIRECT_URI as REDIRECT_URI:
public class Test {
private static Properties prop;
public static void main(String[] args) {
Test a = new Test();
}
public Test() {
// The following code should run after private final String REDIRECT_URI;
try {
System.out.println();
} catch (Exception e) {}
REDIRECT_URI = "REDIRECT_URI";
System.out.println(REDIRECT_URI);
}
private final String REDIRECT_URI;
}
And I also tried to change the constructor like this:
private UnionAuthProperties() {
prop = new Properties();
}
still NPE.