public inbox for java-prs@sourceware.org help / color / mirror / Atom feed
From: "kreijack at inwind dot it" <gcc-bugzilla@gcc.gnu.org> To: java-prs@gcc.gnu.org Subject: [Bug java/21074] New: Trivial bug in the method getHeaderFieldKey() in the file java/net/protocol/http/HTTPURLConnection.java Date: Sun, 17 Apr 2005 18:48:00 -0000 [thread overview] Message-ID: <20050417184836.21074.kreijack@inwind.it> (raw) 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 [ghigo@therra 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++; } } } [ghigo@therra 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. [ghigo@therra 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) [ghigo@therra 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) [ghigo@therra 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 [ghigo@therra 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. [ghigo@therra 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
next reply other threads:[~2005-04-17 18:48 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-04-17 18:48 kreijack at inwind dot it [this message] 2005-04-17 18:52 ` [Bug libgcj/21074] " pinskia at gcc dot gnu dot org 2005-06-15 20:08 ` cvs-commit at gcc dot gnu dot org 2005-06-15 20:10 ` tromey at gcc dot gnu dot org 2005-08-22 18:05 ` tromey at gcc dot gnu dot org 2005-08-22 18:06 ` cvs-commit at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050417184836.21074.kreijack@inwind.it \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=java-prs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).