commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestHttpStatus.java
Date Sun, 02 May 2004 11:21:13 GMT
olegk       2004/05/02 04:21:13

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpStatus.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestHttpStatus.java
  Log:
  PR #28626 (ArrayIndexOutOfBoundsException in HttpStatus.getStatusText(508))
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.18      +8 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java
  
  Index: HttpStatus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- HttpStatus.java	18 Apr 2004 23:51:35 -0000	1.17
  +++ HttpStatus.java	2 May 2004 11:21:13 -0000	1.18
  @@ -75,10 +75,13 @@
        */
       public static String getStatusText(int statusCode) {
   
  +        if (statusCode < 0) {
  +            throw new IllegalArgumentException("status code may not be negative");
  +        }
           int classIndex = statusCode / 100;
           int codeIndex = statusCode - classIndex * 100;
           if (classIndex < 1 || classIndex > (REASON_PHRASES.length - 1) 
  -            || codeIndex < 0 || codeIndex > REASON_PHRASES[classIndex].length) {
  +            || codeIndex < 0 || codeIndex > (REASON_PHRASES[classIndex].length -
1)) {
               return null;
           }
           return REASON_PHRASES[classIndex][codeIndex];
  
  
  
  1.4       +17 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java
  
  Index: TestHttpStatus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHttpStatus.java	22 Feb 2004 18:08:49 -0000	1.3
  +++ TestHttpStatus.java	2 May 2004 11:21:13 -0000	1.4
  @@ -92,4 +92,17 @@
   
       }
   
  +    public void testStatusTextNegative() throws Exception {
  +        try {
  +            HttpStatus.getStatusText(-1);
  +            fail("IllegalArgumentException must have been thrown");
  +        } catch (IllegalArgumentException expected) {
  +        }
  +    }
  +
  +    public void testStatusTextAll() throws Exception {
  +        for (int i = 0; i < 600; i++) {
  +            HttpStatus.getStatusText(i);
  +        }
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message