閱讀729 返回首頁    go 阿裏雲 go 技術社區[雲棲]


剖析在WAS 6.1.0.19上碰到/snoop時執行不完整而出現ClassFormatError

剖析在WAS 6.1.0.19上碰到/snoop時執行不完整而出現ClassFormatError

關鍵字: WAS Linux 6.1.0.19 snoop ClassFormatError

環境RedHat Linux + WAS 6.1.0.19
部署默認的應用程序 DefaultApplication.ear,訪問 /snoop時,出現頁麵顯示不完整,隻顯示 Servlet Name: 並到 Request Information: 這兩項的內容,
然後在頁麵的源碼最下麵有一行,雖然源碼在最後一行,但是顯示卻是顯示在表格上方,即在 Request Information: 下麵
Java代碼 複製代碼
  1. java.lang.ClassFormatError com/ibm/ws/webcontainer/srt/SRTServletRequest$2 unexpected EOF at offset=1240  
java.lang.ClassFormatError com/ibm/ws/webcontainer/srt/SRTServletRequest$2 unexpected EOF at offset=1240


於是隻好看此君隱藏在哪個jar裏了,通過 JarClassFind 發現在 AppServer/plugins/com.ibm.ws.webcontainer_2.0.0.jar 中。

於是隻能通過測試此包是否真的有問題。拷貝一個到另一個目錄下,然後執行
Java代碼 複製代碼
  1. jar xvf com.ibm.ws.webcontainer_2.0.0.jar  
jar xvf com.ibm.ws.webcontainer_2.0.0.jar

在執行解壓的過程當中會出現如下錯誤:
Java代碼 複製代碼
  1. java.util.zip.ZipException: invalid entry size (expected 1240 but got 1242 bytes)   
  2.     at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java(Compiled Code))   
  3.     at java.util.zip.ZipInputStream.read(ZipInputStream.java(Compiled Code))   
  4.     at sun.tools.jar.Main.extractFile(Main.java(Compiled Code))   
  5.     at sun.tools.jar.Main.extract(Main.java:718)   
  6.     at sun.tools.jar.Main.run(Main.java:228)   
  7.     at sun.tools.jar.Main.main(Main.java:994)  
java.util.zip.ZipException: invalid entry size (expected 1240 but got 1242 bytes)
    at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java(Compiled Code))
    at java.util.zip.ZipInputStream.read(ZipInputStream.java(Compiled Code))
    at sun.tools.jar.Main.extractFile(Main.java(Compiled Code))
    at sun.tools.jar.Main.extract(Main.java:718)
    at sun.tools.jar.Main.run(Main.java:228)
    at sun.tools.jar.Main.main(Main.java:994)

隻能說明是包壞了,從另一台機器上麵執行同樣的解壓測試,OK,一切正常,那就下載一個過來,覆蓋後重新啟動之即可。

附Java Doc的解釋為:
Java代碼 複製代碼
  1. public class ClassFormatError extends LinkageError  
public class ClassFormatError extends LinkageError

當 Java 虛擬機試圖讀取類文件並確定該文件存在格式錯誤或無法解釋為類文件時,拋出該錯誤。

Java代碼 複製代碼
  1. unexpected EOF at offset=1240  
unexpected EOF at offset=1240
,應當在1240結束,但卻沒有。

Java代碼 複製代碼
  1. expected 1240 but got 1242 bytes  
expected 1240 but got 1242 bytes
,變多了2個字節,嗬嗬:)
由於在生產環境,壞的包無法拿出來,放上本機正常包的麵目,如下圖:



真是見怪不怪了。

正常情況下/snoop接下來應當是顯示 Request headers: 相關的內容了。

剖析一下看。。。
Java代碼 複製代碼
  1. SnoopServlet.java   
  2.                 e = req.getParameterNames();   
  3.                 if ( e.hasMoreElements() )   
  4.                 {   
  5.                         out.println("<h2>Servlet parameters (Single Value style):</h2>");   
  6.                         out.println("<TABLE Border=/"2/" WIDTH=/"65%/" BGCOLOR=/"#DDDDFF/">");   
  7.                         while ( e.hasMoreElements() )   
  8.                         {   
  9.                                 String name = (String)e.nextElement();   
  10.                                 out.println("<tr><td>" + name + "</td><td>" + req.getParameter(name) + "</td></tr>");   
  11.                         }   
  12.                         out.println("</table><BR><BR>");   
  13.                 }  
SRTServletRequest.java
Java代碼 複製代碼
  1.             public Enumeration getAttributeNames()   
  2.             {   
  3. /* 225*/        if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())   
  4. /* 226*/            Tr.debug(tc, "getAttributeNames [" + this + "]");   
  5. /* 228*/        return new Enumeration() {   
  6.   
  7.                     public boolean hasMoreElements()   
  8.                     {   
  9. /* 231*/                return iter.hasNext();   
  10.                     }   
  11.   
  12.                     public Object nextElement()   
  13.                     {   
  14. /* 235*/                return iter.next();   
  15.                     }   
  16.   
  17.                     private Iterator iter;   
  18.   
  19.                        
  20.                     {   
  21. /* 229*/                iter = _srtRequestHelper._attributes.keySet().iterator();   
  22.                     }   
  23.         }  
說明了什麼問題?匿名類也是僅在需要的時候才去Load,而不是跟主類一並全Load進去。於是 SnoopServlet可以執行一部分,而後麵才出錯。

最後更新:2017-04-02 00:06:48

  上一篇:go Opengl編程學習筆記(五)——從FRAGMENT到PIXEL(framebuffer 幀緩存)
  下一篇:go smarty簡單測試例子