Name: bsC130419 Date: 06/21/2001
java version "1.3.1" [vs. 1.4 -- see below]
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
A call to method test throws IOException, but test doesn't declare any
Exceptions to be thrown.
static URLConnection test(URL url) {
URLConnection uc = null;
try {
uc = url.openConnection();
System.out.println("Response code: " + ((HttpURLConnection)
uc).getResponseCode());
} catch (Throwable t) {
System.out.println("Exception intercepted!");
t.printStackTrace();
} finally {
System.out.println("!!!!! finalize");
try {
System.out.println("!!!!! 1");
((HttpURLConnection)uc).disconnect();
System.out.println("!!!!! 2");
} catch (Throwable t3) {}
System.out.println("!!!!! 3");
}
return uc;
}
public static void main(String args[]) {
try {
String url = "http://javor.pef.uni-lj.si/~ori99/";
URLConnection uc = test(new URL(url));
System.out.println("Done: " + ((HttpURLConnection)uc).getResponseCode()
+ ".");
} catch (Throwable t) {
System.out.println("Error:");
t.printStackTrace();
}
}
Output with JDK 1.4:
Response code: 403
!!!!! finalize
!!!!! 1
!!!!! 2
!!!!! 3
Error:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://jav
or.pef.uni-lj.si/~ori99/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream
(HttpURLConnection.java:558)
at java.net.HttpURLConnection.getResponseCode
(HttpURLConnection.java:235)
at si.noviforum.util.TimeoutURLConnection.test
(TimeoutURLConnection.java:236)
at si.noviforum.util.TimeoutURLConnection.main
(TimeoutURLConnection.java:257)
Output with JDK 1.3.1 (or older):
Response code: 403
!!!!! finalize
!!!!! 1
!!!!! 2
!!!!! 3
Done: 403.
(Review ID: 126937)
======================================================================