關於WAS當中FFDC報告error in opening zip file剖析及解決

阿敏總司令發表於2008-12-23
關於WAS當中FFDC報告java.util.zip.ZipException: error in opening zip file剖析及解決

問題:
WAS下FFDC日誌目錄中出現如下的錯誤,開啟zip檔案錯誤
[code]
FFDC Exception:java.util.zip.ZipException SourceId:com.ibm.ws.classloader.ClassLoaderUtils.addDependents ProbeId:238 Reporter:java.lang.Class@7c537c91
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:133)
at java.util.jar.JarFile.<init>(JarFile.java:70)
at com.ibm.ws.classloader.ClassLoaderUtils.addDependents(ClassLoaderUtils.java:96)
at com.ibm.ws.classloader.ClassLoaderUtils.addDependents(ClassLoaderUtils.java:143)
at com.ibm.ws.classloader.ClassLoaderUtils.addDependentJars(ClassLoaderUtils.java:61)
at com.ibm.ws.classloader.ClassGraph.<init>(ClassGraph.java:115)
at com.ibm.ws.classloader.ClassLoaderManager.initialize(ClassLoaderManager.java:202)
at com.ibm.ws.classloader.ClassLoaderManager.<init>(ClassLoaderManager.java:166)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:891)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:740)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2092)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:437)
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:122)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:380)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$300(CompositionUnitMgrImpl.java:105)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:928)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:349)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
[/code]
那到底是哪個檔案在開啟時發生錯誤了呢?一頭霧水了吧,汗。。。估計你會。。。

分析:
1、通過對檔案的排查,確認排除了應用程式中引用jar檔案損壞的可能性以及由於jar檔案許可權設定導致無法讀取的可能性

2、開啟跟蹤日誌級別進行剖析
[code]
Application servers > memXXX > Logging and Tracing > Change log detail levels
[/code]
設定ClassLoaderUtils跟蹤級別如下
[code]
*=info: com.ibm.ws.classloader.ClassLoaderUtils=finest
[/code]
重新啟動後,在trace.log裡可以發現如下資訊
[code]
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/commons-logging.jar
0000001e ClassLoaderUt 3 dependent classpath detected: log4j.jar log4j-core.jar
0000001e ClassLoaderUt 3 adding /home/xxx/lib/struts/log4j.jar
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/log4j.jar
0000001e FfdcProvider I com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on /usr/IBM/WebSphere/AppServer/profiles/XXX/logs/ffdc/memXXX_f3c3750_08.12.23_16.26.42.85048008.txt com.ibm.ws.classloader.ClassLoaderUtils.addDependents 238
0000001e ClassLoaderUt 3 WARNING: could not open /home/xxx/lib/struts/log4j.jar : error in opening zip file
0000001e ClassLoaderUt < addDependents Exit
/home/xxx/lib/struts/log4j.jar
0000001e ClassLoaderUt 3 adding /home/xxx/lib/struts/log4j-core.jar
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/log4j-core.jar
0000001e ClassLoaderUt 3 WARNING: could not open /home/xxx/lib/struts/log4j-core.jar : error in opening zip file
0000001e ClassLoaderUt < addDependents Exit
/home/xxx/lib/struts/log4j-core.jar
0000001e ClassLoaderUt < addDependents Exit
/home/xxx/lib/struts/commons-logging.jar
......
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/struts.jar
0000001e ClassLoaderUt 3 dependent classpath detected: commons-beanutils.jar commons-collections.jar commons-digester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar struts-legacy.jar
0000001e ClassLoaderUt 3 adding /home/xxx/lib/struts/jakarta-oro.jar
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/jakarta-oro.jar
0000001e ClassLoaderUt 3 WARNING: could not open /home/xxx/lib/struts/jakarta-oro.jar : error in opening zip file
0000001e ClassLoaderUt < addDependents Exit
/home/xxx/lib/struts/jakarta-oro.jar
0000001e ClassLoaderUt 3 adding /home/xxx/lib/struts/struts-legacy.jar
0000001e ClassLoaderUt > addDependents Entry
/home/xxx/lib/struts/struts-legacy.jar
0000001e ClassLoaderUt 3 WARNING: could not open /home/xxx/lib/struts/struts-legacy.jar : error in opening zip file
0000001e ClassLoaderUt < addDependents Exit
/home/xxx/lib/struts/struts-legacy.jar
0000001e ClassLoaderUt < addDependents Exit
......
[/code]

繼續分析:
首先,可以確認的是WARNING所報的是正確的,因為可以通過確認所依賴的log4j.jar log4j-core.jar jakarta-oro.jar struts-legacy.jar之類的檔案不存在。
其次,這些不存在的包是由誰依賴並需要載入的,通過日誌的層次關係可以知道,commons-logging.jar需要log4j.jar log4j-core.jar,struts.jar需要jakarta-oro.jar struts-legacy.jar
這樣唯一的可能就是各自的jar包中META-INF\MANIFEST.MF裡宣告瞭這些jar的依賴關係了。

開啟commons-logging.jar,發現其中的META-INF\MANIFEST.MF裡包含了
Class-Path: log4j.jar log4j-core.jar

開啟struts.jar,發現其中的META-INF\MANIFEST.MF裡包含了
Class-Path: commons-beanutils.jar commons-collections.jar commons-dig
ester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar s
truts-legacy.jar

於是真相大白了,解決的辦法要麼增加相應版本所依賴的jar包,要麼就是簡單地刪除Class-Path,根據應用程式的需要進行確認並使用之,[[size=medium]color=red]建議用前者進行解決。要麼就升級這些元件包。[/color][/size]

程式碼解讀
[code]
ClassLoaderUtils.java
public static String[] addDependentJars(String paths[])
{
ArrayList newPaths = new ArrayList(Arrays.asList(paths));
for(int i = 0; i < paths.length; i++)
if(paths[i].toLowerCase().endsWith(".jar"))
addDependents(paths[i], newPaths);

String result[] = new String[newPaths.size()];
result = (String[])(String[])newPaths.toArray(result);
return result;
}

private static void addDependents(String jarFileName, List classpath)
{
// ...省略。。。
jar = new JarFile(jarFileName);// 錯誤在這一行
manifest = jar.getManifest();
attrs = manifest.getMainAttributes();
dependents = attrs.getValue(java.util.jar.Attributes.Name.CLASS_PATH);// 獲取依賴包路徑
StringTokenizer tokens = new StringTokenizer(dependents, " ");
do
{
if(!tokens.hasMoreTokens())
break;
String nextDependent = tokens.nextToken();
String nextDependentFullPath = (new StringBuilder()).append(prefix).append(nextDependent).
if(PathUtils.listAddNoDup(classpath, nextDependentFullPath))
{
addDependents(nextDependentFullPath, classpath); // 迭代載入之
}
} while(true);
// ...省略。。。
在catch程式碼塊中
catch(ZipException ze)
{
Manager.Ffdc.log(ze, ClassLoaderUtils.class, "com.ibm.ws.classloader.ClassLoaderUtils.addDependents", "238" + jarFileName);
if(debugEnabled)
Tr.debug(tc, (new StringBuilder()).append("WARNING: could not open ").append(jarFileName).append(" : ").append(ze.getLocalizedMessage()).toString());
}
catch(IOException ioe)
{
Manager.Ffdc.log(ioe, ClassLoaderUtils.class, "com.ibm.ws.classloader.ClassLoaderUtils.addDependents", "246");
if(debugEnabled)
Tr.debug(tc, (new StringBuilder()).append("WARNING: I/O exception ").append(jarFileName).append(" : ").append(ioe.getLocalizedMessage()).toString());
}
[/code]

[size=large][color=red]不厚道,在Manager.Ffdc.log裡把jarFileName也列印出來,就更容易知道是什麼問題了。
可見列印出有意義的資訊對於分析問題是多少的重要。。。[/color][/size]

附帶資訊:將commons-logging.jar與struts.jar與Spring 2.5.5釋出所帶的包進行對比分析,發現Spring帶的commons-logging.jar包沒有帶有Class-Path這個條目。
[code]
Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Extension-Name: org.apache.commons.logging
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.0
Implementation-Vendor: Apache Software Foundation
Implementation-Version: 1.0.3
Class-Path: log4j.jar log4j-core.jar
[/code]

對比
[code]
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: dlg01
Build-Jdk: 1.4.2_16
Implementation-Title: Commons Logging
Implementation-Vendor: Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.1.1
Specification-Title: Commons Logging
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.0
X-Compile-Source-JDK: 1.2
X-Compile-Target-JDK: 1.1
Extension-Name: org.apache.commons.logging
[/code]

注意實現的版本問題是不同的

struct.jar包的條目內容不同
[code]
Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Extension-Name: Struts Framework
Specification-Title: Struts Framework
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.1
Implementation-Title: Struts Framework
Implementation-Vendor: Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.1
Class-Path: commons-beanutils.jar commons-collections.jar commons-dig
ester.jar commons-logging.jar commons-validator.jar jakarta-oro.jar s
truts-legacy.jar
[/code]

對比
[code]
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.1
Created-By: 1.3.1_04-b02 (Sun Microsystems Inc.)
Extension-Name: Struts Framework
Specification-Title: Struts Framework
Specification-Vendor: The Apache Software Foundation
Specification-Version: 1.2.9
Implementation-Title: Struts Framework
Implementation-Vendor: The Apache Software Foundation
Implementation-Vendor-Id: org.apache
Implementation-Version: 1.2.9
Class-Path: commons-beanutils.jar commons-digester.jar commons-fileup
load.jar commons-logging.jar commons-validator.jar jakarta-oro.jar
[/code]
也要注意實現的版本問題是不同的

相關文章