[pool-1-thread-1] ERROR: org.androidpn.server.xmpp.net.XmppIoHandlerexceptionCaught : java.lang.ExceptionInInitializerError
这个是第一个异常,这个异常发生之后,会接着很多个如下异常:
[pool-1-thread-10] ERROR: org.androidpn.server.xmpp.net.XmppIoHandlerexceptionCaught : java.lang.NoClassDefFoundError: Could not initialize class org.androidpn.server.xmpp.ssl.SSLConfig
上个礼拜要提交项目的时候才留意到这么一行异常(因为之前用了struts的token,所以后台很多token的警告,所以没有留意长长的一段异常文字),于是自己debug了一下,找到了引起异常的地方,就是一个空指针的异常,说出来还真是没有什么得意的地方:
private static URL classPath ;
static {
storeType = Config.getString("xmpp.ssl.storeType", "JKS");
keyStoreLocation = Config.getString("xmpp.ssl.keystore", "conf"
+ File.separator + "security" + File.separator + "keystore");
keyStoreLocation = classPath.getPath() + File.separator
+ keyStoreLocation;
keyPass = Config.getString("xmpp.ssl.keypass", "changeit");
trustStoreLocation = Config.getString("xmpp.ssl.truststore", "conf"
+ File.separator + "security" + File.separator + "truststore");
trustStoreLocation = classPath.getPath()
+ File.separator + trustStoreLocation;
trustPass = Config.getString("xmpp.ssl.trustpass", "changeit");
classPath = SSLConfig.class.getResource("/");
看到classPath,很明显,这个classPath会引起空指针异常,所以,只要把classPath = SSLConfig.class.getResource("/");往上提,提到static块里面的第一行,就ok了。
想来应该是写这个版本的人有点不小心所致,不过问题不大,仍然感谢他的奉献精神,各位有看到这种异常的,还希望对大家有帮助。
今天(20120801)又看到一个Bug,还是在SSLConfig上面:
[pool-1-thread-1] ERROR: org.androidpn.server.xmpp.ssl.SSLConfig<clinit> : SSLConfig startup problem.
这一个错误由路径错误引起,因为编码格式的问题,如果路径中存在空格,会变成%20这样的字符,所以只要确保路径正确,就ok了。Bug出现还是在classPath的初始化上面:
// Load keystore
try {
keyStore = KeyStore.getInstance(storeType);
keyStore.load(new FileInputStream(URLDecoder.decode(keyStoreLocation)), keyPass
.toCharArray());
}
还是在静态初始化块这里,把keyStoreLocation换成这种初始方式就不会出现找不到路径这样的错误了。
如果有错,还希望指出。