classpath-inetlib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Classpath-inetlib] Bug in Revision 1.3 of gnu/inet/nntp/NNTPConnection.


From: bodo.weiss
Subject: [Classpath-inetlib] Bug in Revision 1.3 of gnu/inet/nntp/NNTPConnection.java
Date: Fri, 30 Apr 2004 17:48:01 +0200

The method listGroup uses the wrong constant in the first line of the
methods body
LIST_NEWSGROUPS = "LIST NEWSGROUPS" 
LISTGROUP = "LISTGROUP" 

public ArticleNumberIterator listGroup(String group) throws IOException
  {
    // was StringBuffer buffer = new StringBuffer(LIST_NEWSGROUPS);
    StringBuffer buffer = new StringBuffer(LISTGROUP);
    if (group != null)
    {
      buffer.append(' ');
      buffer.append(group);
    }
    send(buffer.toString());
    StatusResponse response = parseResponse(read());
    switch (response.status)
    {
      case GROUP_SELECTED:
        ArticleNumberIterator ani = new ArticleNumberIterator(this);
        pendingData = ani;
        return ani;
      default:
        throw new NNTPException(response);
    }
  }

After this bug is solved, there is a new problem.
The command LISTGROUP returns this String from my NNTP-Server 
    211 Article list follows
This string cause the method parseResponse to throw a
NumberFormatException. Catching the NumberFormatException solves the bug
for me.



  protected StatusResponse parseResponse(String line)
  {
    int start = 0, end;
    String statusText = line;
    String message = null;
    end = line.indexOf(' ', start);
    if (end > start)
    {
      statusText = line.substring(start, end);
      message = line.substring(end + 1);
    }
    short status = Short.parseShort(statusText);
    StatusResponse response;
    switch (status)
    {
      case ARTICLE_FOLLOWS:
      case HEAD_FOLLOWS:
      case BODY_FOLLOWS:
      case ARTICLE_RETRIEVED:
        try
        {
          ArticleResponse aresponse = new ArticleResponse(status,
message);
          // article number
          start = end + 1;
          end = line.indexOf(' ', start);
          if (end > start)
            aresponse.articleNumber =
              Integer.parseInt(line.substring(start, end));
          // message-id
          start = end + 1;
          end = line.indexOf(' ', start);
          if (end > start)
            aresponse.messageId = line.substring(start, end);
          else
            aresponse.messageId = line.substring(start);
          response = aresponse;
        }
        catch(NumberFormatException e)
        {
          // This will happen for XHDR
          response = new StatusResponse(status, message);
        }
        break;
      case GROUP_SELECTED:
  GroupResponse gresponse = new GroupResponse(status, message);
// Next line added
try {
// count
start = end + 1;
end = line.indexOf(' ', start);
if (end > start)
  gresponse.count = Integer.parseInt(line.substring(start, end));
// first
start = end + 1;
end = line.indexOf(' ', start);
if (end > start)
  gresponse.first = Integer.parseInt(line.substring(start, end));
// last
start = end + 1;
end = line.indexOf(' ', start);
if (end > start)
  gresponse.last = Integer.parseInt(line.substring(start, end));
// group
start = end + 1;
end = line.indexOf(' ', start);
if (end > start)
  gresponse.group = line.substring(start, end);
else
  gresponse.group = line.substring(start);
// Next line added
} catch (NumberFormatException e1) {}
response = gresponse;
        break;
      default:
        response = new StatusResponse(status, message);
    }
    return response;
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]