[悬赏 - 已结束]一杯星巴克咖啡-本文中的异常栈原理(Runtime异常抛出后,后面代码竟然继续执行)

[最新状态]
被RobertLee秒杀了,任何一个调用层次都可以打印全栈异常信息。本文最后给出了一个小例子:[印证任何一个调用层次都可以打印全栈信息的例子]
--20150615
 
[总结]
本文的提出,是对打印全栈(full stack)异常的知识的错误认识引起的。
大家只要牢记:调用链中的任何一个节点在打印stack trace的时候,都可以将全栈信息(调用的最顶端到异常发生的最底端)打印出来。
下面给一个例子:  [印证任何一个调用层次都可以打印全栈信息的例子]
package baoying.java.lang;
 
public class ExceptionStackPrint {
 
 public static void main(String[] args) {
/**
print exception at B_A
java.lang.RuntimeException: D_C_B_A
 at baoying.java.lang.D_C_B_A.execute(ExceptionStackPrint.java:48)
 at baoying.java.lang.C_B_A.execute(ExceptionStackPrint.java:41)
 at baoying.java.lang.B_A.execute(ExceptionStackPrint.java:28)
 at baoying.java.lang.A.execute(ExceptionStackPrint.java:21)
 at baoying.java.lang.ExceptionStackPrint.main(ExceptionStackPrint.java:15)
 */
  new A().execute();
 }
}
 
class A{
 public void execute(){
  new B_A().execute();
 }
}
 
class B_A{
 public void execute(){
  try{
  new C_B_A().execute();
  }catch(Throwable t){
   System.out.println("print exception at B_A");
   t.printStackTrace();
   
  }
 }
 
}
 
class C_B_A{
 
 public void execute(){
  new D_C_B_A().execute();
 }
}
 
class D_C_B_A{
 
 public void execute(){
  throw new RuntimeException("D_C_B_A");
 }
}
 
====下面是原来的问题悬赏部分====
其实了解了上面的关于打印全栈信息的知识,下面的问题就不是问题了。
问题:
1. Image iconImg = Toolkit.getDefaultToolkit().getImage(url);
2. System.out.println(threadInfo+ " "+ new java.util.Date()+method+" load done:"+imageInCP);
行1 中抛出了runtimeexception, 问什么为什么行2 .能运行打印log?
更详细的异常栈,所有log以及源码下面已给出。
 
注: 程序运行环境为java applet。1.8.0-45.
 
如果您知道原因,并不吝赐教,非常感谢。请留下联系方式或联系我 qq:35131698, 微信:王保迎。 一杯星巴克咖啡 - 先到先得,我不是土豪 酷 。不爱喝星巴克?等值礼品也行:)
最新进展更新在我的有道云笔记中。不定期更新到本blog
 
 
这log用我的iPhone5S看,格式像一坨屎一样。您的iPhone 6 plus可能好一点点。
 
[log如下]  
 
Baoying Thread - 19783394485810 is Created  
Baoying Thread - 19783394485810 Started  
Baoying Thread - 19783394485810:98 wait 30 seconds to let you be ready, and thread will start after sleep  
cache: Create from verifier: JarSigningData{hasOnlySignedEntries=true, hasSingleCodeSource=true, hasMissingSignedEntries=false}  
cache: Upgrade of entry done  
cache: readIndexFile returning success  
network: CleanupThread used 1952979 us  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:50:57 CST 2015getImageByURL: try to load:/baoying.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:50:57 CST 2015getImageByURL: load url:jar:https://huhuzhu-scs.nott.ime.reuters.com/ptshub/baoying/BaoyingImageShow.jar!/baoying.JPG  
network: Cache entry not found [url: http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml, version: null]  
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml with proxy=DIRECT  
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com:80/ with proxy=DIRECT  
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml with cookie "63738647932733330794D3=E4F34636C61336A3F6B554; D693E3D38686E6D3E65655F36523964614D683E4041595E4452676F466C5A363D3=A4348516A307F376246553; D693E3D38686E6D3E656550505F3F34656D47334D69595F415642355639407D654=8574E3C644D32364346514; D693E3D38686E6D3E656550505F3F34656D47334D6952375F405F61385057517D4=1426633655C637732795D4; https%3A%2F%2Fhuhuzhu-scs.nott.ime.reuters.com%2Fptshub%2Ftheme=m%3Aid%7Cs%3Areuters%2Cfile%7Cs%3Axtheme-reuters.css"  
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com:80/ with proxy=DIRECT  
java.net.SocketException: Connection reset  
at java.net.SocketInputStream.read(Unknown Source)  
at java.net.SocketInputStream.read(Unknown Source)  
at java.io.BufferedInputStream.fill(Unknown Source)  
at java.io.BufferedInputStream.read1(Unknown Source)  
at java.io.BufferedInputStream.read(Unknown Source)  
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)  
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)  
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)  
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)  
at sun.net.www.protocol.http.HttpURLConnection.access$200(Unknown Source)  
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)  
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source)  
at java.security.AccessController.doPrivileged(Native Method)  
at java.security.AccessController.doPrivileged(Unknown Source)  
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)  
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)  
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)  
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)  
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)  
at java.net.InetAddress.getAllByName0(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getByName(Unknown Source)  
at java.net.URLStreamHandler.getHostAddress(Unknown Source)  
at java.net.URLStreamHandler.hashCode(Unknown Source)  
at java.net.URL.hashCode(Unknown Source)  
at sun.net.www.protocol.jar.Handler.hashCode(Unknown Source)  
at java.net.URL.hashCode(Unknown Source)  
at java.util.HashMap.hash(Unknown Source)  
at java.util.HashMap.get(Unknown Source)  
at sun.misc.SoftCache.get(Unknown Source)  
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)  
at sun.awt.SunToolkit.getImage(Unknown Source)  
at   ImageShowApplet.getImageByURL(ImageShowApplet.java:68)
at ImageShowApplet$1.run(ImageShowApplet.java:37)  
at java.lang.Thread.run(Unknown Source)  
java.security.AccessControlException: access denied ("java.net.SocketPermission" "huhuzhu-scs.nott.ime.reuters.com" "resolve")  
at java.security.AccessControlContext.checkPermission(Unknown Source)  
at java.security.AccessController.checkPermission(Unknown Source)  
at java.lang.SecurityManager.checkPermission(Unknown Source)  
at java.lang.SecurityManager.checkConnect(Unknown Source)  
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)  
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)  
at java.net.InetAddress.getAllByName0(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getByName(Unknown Source)  
at com.sun.deploy.net.CrossDomainXML.addAccess(Unknown Source)  
at com.sun.deploy.net.CrossDomainXML.allowNoAccess(Unknown Source)  
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)  
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)  
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)  
at java.net.InetAddress.getAllByName0(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getAllByName(Unknown Source)  
at java.net.InetAddress.getByName(Unknown Source)  
at java.net.URLStreamHandler.getHostAddress(Unknown Source)  
at java.net.URLStreamHandler.hashCode(Unknown Source)  
at java.net.URL.hashCode(Unknown Source)  
at sun.net.www.protocol.jar.Handler.hashCode(Unknown Source)  
at java.net.URL.hashCode(Unknown Source)  
at java.util.HashMap.hash(Unknown Source)  
at java.util.HashMap.get(Unknown Source)  
at sun.misc.SoftCache.get(Unknown Source)  
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)  
at sun.awt.SunToolkit.getImage(Unknown Source)  
at   ImageShowApplet.getImageByURL(ImageShowApplet.java:68)
at ImageShowApplet$1.run(ImageShowApplet.java:37)  
at java.lang.Thread.run(Unknown Source)  
--问题在此:问什么下面这行log能打印出来?按照上面的调用栈,已经明确表示在ImageShowApplet.java:68已经抛出AccessControlException,那么下面的程序应该无法继续执行。线程应该终止。但是程序继续执行,而且还是那个线程。真是百思不得其姐 !
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:07 CST 2015getImageByURL: load done:/baoying.JPG
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:07 CST 2015getImageByURL: try to load:/baoying_02.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:07 CST 2015getImageByURL: load url:jar:https://huhuzhu-scs.nott.ime.reuters.com/ptshub/baoying/BaoyingImageShow.jar!/baoying_02.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:12 CST 2015getImageByURL: load done:/baoying_02.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:12 CST 2015getImageByURL: try to load:/baoying_03.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:12 CST 2015getImageByURL: load url:jar:https://huhuzhu-scs.nott.ime.reuters.com/ptshub/baoying/BaoyingImageShow.jar!/baoying_03.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:16 CST 2015getImageByURL: load done:/baoying_03.JPG  
Baoying Thread - 19783394485810:98 re-try the loaded pic baoying_03.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:16 CST 2015getImageByURL: try to load:/baoying_03.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:16 CST 2015getImageByURL: load url:jar:https://huhuzhu-scs.nott.ime.reuters.com/ptshub/baoying/BaoyingImageShow.jar!/baoying_03.JPG  
Baoying Thread - 19783394485810:98 Fri Jun 12 14:51:30 CST 2015getImageByURL: load done:/baoying_03.JPG
 
 
 
[代码如下]
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
 
public class ImageShowApplet extends Applet {
 
 private static final long serialVersionUID = 1L;
 
 Thread t = null;
 public void paint(Graphics g) {
  g.drawString("Welcome in Java Applet.", 40, 20);
 
 
 
  synchronized(this){
   if(t == null){
   
    String id = String.valueOf(System.nanoTime());
    String threadName = "Baoying Thread - " + id;
    t = new Thread(new Runnable(){
     public void run(){
     
      long threadID = Thread.currentThread().getId();
      String name = Thread.currentThread().getName();
      String nameAndID = name +":" + threadID;
     
      System.out.println(nameAndID + " wait 30 seconds to let you be ready, and thread will start after sleep");
      try {
       Thread.sleep(30 * 1000);
      } catch (InterruptedException e) {
       System.out.println(nameAndID + " interrupted exception");
       e.printStackTrace();
      }
     
      getImageByURL("/baoying.JPG",nameAndID);
      getImageByURL("/baoying_02.JPG",nameAndID);
      getImageByURL("/baoying_03.JPG",nameAndID);
     
      System.out.println(nameAndID + " re-try the loaded pic baoying_03.JPG");
      getImageByURL("/baoying_03.JPG",nameAndID);
      //getImageByFilename();
     
     }
    },threadName);
    System.out.println(threadName+" is Created");
   
    t.start();
    System.out.println(threadName + " Started");
 
   }
  }
 }
 
 public void getImageByURL(String imageInCP, String threadInfo){
 
  String method = "getImageByURL:";
 
  System.out.println(threadInfo+ " "+ new java.util.Date()+method+" try to load:"+imageInCP);
  URL url = this.getClass().getResource(imageInCP);
     if(url == null){
      System.out.println(threadInfo+ " "+ new java.util.Date()+method+" null url by:"+imageInCP);
      return;
     }
     System.out.println(threadInfo+ " "+ new java.util.Date()+method+" load url:"+url.toString());
     
     Image iconImg = Toolkit.getDefaultToolkit().getImage(url);
     if(iconImg == null){
      System.out.println(threadInfo+ " "+ new java.util.Date()+method+" null image by:"+imageInCP);
      return;
     }
     System.out.println(threadInfo+ " "+ new java.util.Date()+method+" load done:"+imageInCP);
 
 }
}
 
 
[运行环境]
将上述applet部署在远端apache服务器上,通过域名调用。
本地jre为 1.8.0_45

 

[参考]

Another guy(by eagleanec - 2012-08-21 00:58) with similar trace

https://weblogs.java.net/blog/2008/05/28/java-doodle-crossdomainxml-support

 

another report with same stack trace

https://community.oracle.com/thread/2179788

 

还有一个csdn的,无满意回复而结贴

http://bbs.csdn.net/topics/360101851

 

台湾朋友也有这个trace on java8 update 25
 
BTW: 细心的朋友可以看到,其实上面连续抛出了两个异常,起源是一样的。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

java.security.AccessControlException: access denied ("java.net.SocketPermission" "huhuzhu-scs.nott.ime.reuters.com" "resolve") 
at java.security.AccessControlContext.checkPermission(Unknown Source) 
at java.security.AccessController.checkPermission(Unknown Source) 
at java.lang.SecurityManager.checkPermission(Unknown Source) 
at java.lang.SecurityManager.checkConnect(Unknown Source) 
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source) 
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source) 
at java.net.InetAddress.getAllByName0(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getByName(Unknown Source) 
at com.sun.deploy.net.CrossDomainXML.addAccess(Unknown Source) 
at com.sun.deploy.net.CrossDomainXML.allowNoAccess(Unknown Source) 
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source) 
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source) 
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source) 
at java.net.InetAddress.getAllByName0(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getByName(Unknown Source) 
at java.net.URLStreamHandler.getHostAddress(Unknown Source) 
at java.net.URLStreamHandler.hashCode(Unknown Source) 
at java.net.URL.hashCode(Unknown Source) 
at sun.net.www.protocol.jar.Handler.hashCode(Unknown Source) 
at java.net.URL.hashCode(Unknown Source) 
at java.util.HashMap.hash(Unknown Source) 
at java.util.HashMap.get(Unknown Source) 
at sun.misc.SoftCache.get(Unknown Source) 
at sun.awt.SunToolkit.getImageFromHash(Unknown Source) 
at sun.awt.SunToolkit.getImage(Unknown Source) 

at ImageShowApplet.getImageByURL(ImageShowApplet.java:68)
at ImageShowApplet$1.run(ImageShowApplet.java:37) 
at java.lang.Thread.run(Unknown Source) 

Baoying Thread - 19783394485810:98 Fri Jun 12 14:50:57 CST 2015getImageByURL: load url:jar:https://huhuzhu-scs.nott.ime.reuters.com/ptshub/baoying/BaoyingImageShow.jar!/baoying.JPG 
network: Cache entry not found [url: http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml, version: null]    
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml with proxy=DIRECT 
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com:80/ with proxy=DIRECT 
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com/crossdomain.xml with cookie "63738647932733330794D3=E4F34636C61336A3F6B554; D693E3D38686E6D3E65655F36523964614D683E4041595E4452676F466C5A363D3=A4348516A307F376246553; D693E3D38686E6D3E656550505F3F34656D47334D69595F415642355639407D654=8574E3C644D32364346514; D693E3D38686E6D3E656550505F3F34656D47334D6952375F405F61385057517D4=1426633655C637732795D4; https%3A%2F%2Fhuhuzhu-scs.nott.ime.reuters.com%2Fptshub%2Ftheme=m%3Aid%7Cs%3Areuters%2Cfile%7Cs%3Axtheme-reuters.css" 
network: Connecting http://huhuzhu-scs.nott.ime.reuters.com:80/ with proxy=DIRECT 
java.net.SocketException: Connection reset 
at java.net.SocketInputStream.read(Unknown Source) 
at java.net.SocketInputStream.read(Unknown Source) 
at java.io.BufferedInputStream.fill(Unknown Source) 
at java.io.BufferedInputStream.read1(Unknown Source) 
at java.io.BufferedInputStream.read(Unknown Source) 
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source) 
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source) 
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.access$200(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection$9.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.AccessController.doPrivileged(Unknown Source) 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source) 
at com.sun.deploy.net.CrossDomainXML.check(Unknown Source) 
at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source) 
at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getAllByName(Unknown Source) 
at java.net.InetAddress.getByName(Unknown Source) 
at java.net.URLStreamHandler.getHostAddress(Unknown Source) 
at java.net.URLStreamHandler.hashCode(Unknown Source) 
at java.net.URL.hashCode(Unknown Source) 
at sun.net.www.protocol.jar.Handler.hashCode(Unknown Source) 
at java.net.URL.hashCode(Unknown Source) 
at java.util.HashMap.hash(Unknown Source) 
at java.util.HashMap.get(Unknown Source) 
at sun.misc.SoftCache.get(Unknown Source) 
at sun.awt.SunToolkit.getImageFromHash(Unknown Source) 
at sun.awt.SunToolkit.getImage(Unknown Source) 

at ImageShowApplet.getImageByURL(ImageShowApplet.java:68)
at ImageShowApplet$1.run(ImageShowApplet.java:37) 
at java.lang.Thread.run(Unknown Source) 

 
 

 

你可能感兴趣的:(java)