Hi, I found a little bug in the implementention of the method getHeaderFieldKey( int index ) in the file java/net/protocol/http/HTTPURLConnection.java. This method doesn't check if the parameter 'index' if out of range, so if it is called with a index value too high a java.util.NoSuchElementException is raised. Instead the java doc ( http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html#getHeaderFieldKey(int) ) report that this method should return 'the value of the nth header field, or null if the value does not exist.' I suggest this patch to correct this beaviour; the patch implement the same control performed by the method getHeaderField( ). --- old/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java Sun Apr 17 11:10:59 2005 +++ new/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java Sun Apr 17 11:13:53 2005 @@ -543,6 +543,10 @@ int count = 1; do { + if (!i.hasNext()) + { + return null; + } entry = (Map.Entry) i.next(); count++; } Below are the test case used to highligh the problem, comparing the beaviour of the sun's java and the gnu one. The last case is a case with the patch applied [EMAIL PROTECTED] tmp]$ cat testbed.java import java.net.*; public class testbed { static public void main( String args[] ) throws Exception { URL u=new URL(args[0]); HttpURLConnection con = (HttpURLConnection)u.openConnection(); int n=1; while(true){ String headerKey = con.getHeaderFieldKey(n); if(headerKey==null ){ System.out.print("con.getHeaderFieldKey( ) has returned null\n"); break; } System.out.print("headerKey: "+headerKey+"\n"); String headerVal = con.getHeaderField(n); System.out.print("headerVal: "+headerVal+"\n"); n++; } } } [EMAIL PROTECTED] tmp]$ java -version # Fedora core 4 test 2 java version "1.4.2" gcj (GCC) 4.0.0 20050405 (Red Hat 4.0.0-0.40) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [EMAIL PROTECTED] tmp]$ java -cp . testbed http://www.google.com headerKey: Cache-Control headerVal: private headerKey: Content-Type headerVal: text/html headerKey: Set-Cookie headerVal: PREF=ID=158312593220e9b1:LD=it:TM=1113727883:LM=1113727883:S=Y7zUs9KFT_BVs6d7; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.it headerKey: Server headerVal: GWS/2.1 headerKey: Transfer-Encoding headerVal: chunked headerKey: Date headerVal: Sun, 17 Apr 2005 08:51:23 GMT Exception in thread "main" java.util.NoSuchElementException at java.util.LinkedHashMap$1.next() (/usr/lib/libgcj.so.6.0.0) at gnu.java.net.protocol.http.HTTPURLConnection.getHeaderFieldKey(int) (/usr/lib/libgcj.so.6.0.0) at testbed.main(java.lang.String[]) (Unknown Source) at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0) at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0) [EMAIL PROTECTED] tmp]$ /usr/local/java-1.5/jdk1.5.0_01/bin/java -version java version "1.5.0_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08) Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing) [EMAIL PROTECTED] tmp]$ /usr/local/java-1.5/jdk1.5.0_01/bin/java -cp . testbed http://www.google.com headerKey: Cache-Control headerVal: private headerKey: Content-Type headerVal: text/html headerKey: Set-Cookie headerVal: PREF=ID=81a840411c05e572:LD=it:TM=1113727895:LM=1113727895:S=B5ZxkSzn6RkPyhGV; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.it headerKey: Server headerVal: GWS/2.1 headerKey: Transfer-Encoding headerVal: chunked headerKey: Date headerVal: Sun, 17 Apr 2005 08:51:35 GMT con.getHeaderFieldKey( ) has returned null The last example was executed with the patch applied to the java library [EMAIL PROTECTED] tmp]$ /opt/gcc-4.0.0-20050410/bin/gcj-400 --version gcj-400 (GCC) 4.0.0 20050410 (prerelease) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [EMAIL PROTECTED] tmp]$ CLASSPATH=.:/opt/gcc-4.0.0-20050410/lib \ /opt/gcc-4.0.0-20050410/bin/gij-400 testbed http://www.google.com http://www.google.com headerKey: Cache-Control headerVal: private headerKey: Content-Type headerVal: text/html headerKey: Set-Cookie headerVal: PREF=ID=bb14539184e1692b:LD=it:TM=1113763098:LM=1113763098:S=DpuOWd-IfDkN2-tO; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.it headerKey: Server headerVal: GWS/2.1 headerKey: Transfer-Encoding headerVal: chunked headerKey: Date headerVal: Sun, 17 Apr 2005 18:38:18 GMT con.getHeaderFieldKey( ) has returned null Ciao Goffredo
-- Summary: Trivial bug in the method getHeaderFieldKey() in the file java/net/protocol/http/HTTPURLConnection.java Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kreijack at inwind dot it CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21074