Bug 24084 - HttpUrlConnection getHeaderFieldKey throws NoSuchElementException
Summary: HttpUrlConnection getHeaderFieldKey throws NoSuchElementException
Status: RESOLVED WORKSFORME
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-27 16:35 UTC by Phil Shaw
Modified: 2005-09-27 19:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Sorry, an earlier draft got uploaded, this does not compile, see follow-up attachment. (607 bytes, text/plain)
2005-09-27 16:37 UTC, Phil Shaw
Details
Simple test case for bug. (588 bytes, text/plain)
2005-09-27 16:48 UTC, Phil Shaw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Shaw 2005-09-27 16:35:22 UTC
Fresh install of FC4 with GCJ libgcj-4.0.0 in classpath -- sorry, don't know
what version of Classpath that is. If you call the getHeaderFieldKey method with
a header index that is out of range, it throws a NoSuchElementException rather
than return null. This is a regression against GCJ 3.3.4.
Comment 1 Phil Shaw 2005-09-27 16:37:40 UTC
Created attachment 9819 [details]
Sorry, an earlier draft got uploaded, this does not compile, see follow-up attachment.

Compile and run the main method without any arguments. It creates an URL, makes
an URLConnection and requests a header key out of index.
Comment 2 Phil Shaw 2005-09-27 16:43:25 UTC
Comment on attachment 9819 [details]
Sorry, an earlier draft got uploaded, this does not compile, see follow-up attachment.

package com.mkdoc.bug;

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

import java.util.NoSuchElementException;

public class HttpHeaderFieldKeyTest {

	/**
     *	A test URL from which to get headers.
     */
    private static final String TEST_URL = "http://test.mksearch.mkdoc.org/";

	/**
     *	Index out of range.
     */
    private static final int INDEX = 94860;

    /**
     *	Run the test, no arguments.
     */
    public static final void main(String[] args) {

	URL url = null;

	URLConnection connection = null;

	try {

	    url = new URL(TEST_URL);

	    connection = url.openConnection();

	    connection.connect();   

	    try {

		String header = connection.getHeaderFieldKey(INDEX);

		if (header == null) {

		    System.out.println("Test passes, method returned null.");
		}
		else {

		    System.err.println("Test fails, header at index " +
				       INDEX + 
				       " has value '" +
				       header +
				       "'.");
		}
	    }
	    catch (NoSuchElementException nsee) {

		System.err.println("Test fails, NoSuchElementException
thrown.");
	    }
	}
	catch (IOException ioe) {

	    System.err.println("Test did not run, connection error for URL " +
			       TEST_URL);	 
	}

    }

}
Comment 3 Phil Shaw 2005-09-27 16:44:06 UTC
Comment on attachment 9819 [details]
Sorry, an earlier draft got uploaded, this does not compile, see follow-up attachment.

package com.mkdoc.bug;

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

import java.util.NoSuchElementException;

public class HttpHeaderFieldKeyTest {

	/**
     *	A test URL from which to get headers.
     */
    private static final String TEST_URL = "http://test.mksearch.mkdoc.org/";

	/**
     *	Index out of range.
     */
    private static final int INDEX = 94860;

    /**
     *	Run the test, no arguments.
     */
    public static final void main(String[] args) {

	URL url = null;

	URLConnection connection = null;

	try {

	    url = new URL(TEST_URL);

	    connection = url.openConnection();

	    connection.connect();   

	    try {

		String header = connection.getHeaderFieldKey(INDEX);

		if (header == null) {

		    System.out.println("Test passes, method returned null.");
		}
		else {

		    System.err.println("Test fails, header at index " +
				       INDEX + 
				       " has value '" +
				       header +
				       "'.");
		}
	    }
	    catch (NoSuchElementException nsee) {

		System.err.println("Test fails, NoSuchElementException
thrown.");
	    }
	}
	catch (IOException ioe) {

	    System.err.println("Test did not run, connection error for URL " +
			       TEST_URL);	 
	}

    }

}
Comment 4 Phil Shaw 2005-09-27 16:47:17 UTC
Comment on attachment 9819 [details]
Sorry, an earlier draft got uploaded, this does not compile, see follow-up attachment.

>package com.mkdoc.bug;
>
>import java.io.IOException;
>
>import java.net.URL;
>import java.net.URLConnection;
>
>import java.util.NoSuchElementException;
>
>public class HttpHeaderFieldKeyTest {
>
>	/**
>     *  A test URL from which to get headers.
>     */
>    private static final String TEST_URL = "http://test.mksearch.mkdoc.org/";
> 
> 	/**
>     *  Index out of range.
>     */
>    private static final int INDEX = 94860;
>   
>    /**
>     *  Run the test, no arguments.
>     */
>    public static final void main(String[] args) {
>    
>        URL url = null;
>        
>        URLConnection connection = null;
>        
>        try {
>        
>            url = new URL(TEST_URL);
>            
>            connection = url.openConnection();
>         
>            connection.connect();   
>
>            try {
> 
>                String header = connection.getHeaderFieldKey(INDEX);
>        
>                if (header == null) {
>
>                    System.out.println("Test passes, method returned null.");
>                }
>                else {
>        
>                    System.err.println("Test fails, header at index " +
>                                       INDEX + 
>                                       " has value '" +
>                                       header +
>                                       "'.");
>                }
>            }
>            catch (NoSuchElementException nsee) {
>        
>                System.err.println("Test fails, NoSuchElementException thrown.");
>            }
>        }
>        catch (IOException ioe) {
>
>            System.err.println("Connection error for URL " +
>                               TEST_URL);        
>        }
>        finally {
>        
>            if (connection != null) {
>            
>                connection.disconnect();   
>            }
>        }
>        
>    }
>
>}

Sorry, an earlier draft got uploaded, this does not compile, see follow-up.



package com.mkdoc.bug;

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

import java.util.NoSuchElementException;

public class HttpHeaderFieldKeyTest {

	/**
     *	A test URL from which to get headers.
     */
    private static final String TEST_URL = "http://test.mksearch.mkdoc.org/";

	/**
     *	Index out of range.
     */
    private static final int INDEX = 94860;

    /**
     *	Run the test, no arguments.
     */
    public static final void main(String[] args) {

	URL url = null;

	URLConnection connection = null;

	try {

	    url = new URL(TEST_URL);

	    connection = url.openConnection();

	    connection.connect();   

	    try {

		String header = connection.getHeaderFieldKey(INDEX);

		if (header == null) {

		    System.out.println("Test passes, method returned null.");
		}
		else {

		    System.err.println("Test fails, header at index " +
				       INDEX + 
				       " has value '" +
				       header +
				       "'.");
		}
	    }
	    catch (NoSuchElementException nsee) {

		System.err.println("Test fails, NoSuchElementException
thrown.");
	    }
	}
	catch (IOException ioe) {

	    System.err.println("Test did not run, connection error for URL " +
			       TEST_URL);	 
	}

    }

}
Comment 5 Phil Shaw 2005-09-27 16:48:47 UTC
Created attachment 9820 [details]
Simple test case for bug.

Compile and run main method without arguments.
Comment 6 David Daney 2005-09-27 19:52:19 UTC
Just ran the testcase on: $ gcj --version
gcj (GCC) 4.1.0 20050926 (experimental)

This is the output obtained:

$ ./HttpHeaderFieldKeyTest
Test passes, method returned null.
$