Menu

#2 IndexOutOfBoundsException

open
nobody
None
2
2007-10-28
2007-04-29
No

i'm getting IndexOutOfBoundsException in

optimisticUnchoke()

do-while loop iterates if p (Peer) is null, even if unchokeList is empty.

do {
...
} while (p == null && !this.unchokeList.isEmpty());

should fix the problem.

here's the stack trace:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.LinkedList.entry(LinkedList.java:365)
at java.util.LinkedList.remove(LinkedList.java:357)
at jBittorrentAPI.DownloadManager.optimisticUnchoke(DownloadManager.java:619)
at jBittorrentAPI.DownloadManager.unchokePeers(DownloadManager.java:608)
at jBittorrentAPI.DownloadManager.blockUntilCompletion(DownloadManager.java:171)
at jBittorrentAPI.ExampleDownloadFiles.<init>(ExampleDownloadFiles.java:65)
at jBittorrentAPI.ExampleDownloadFiles.main(ExampleDownloadFiles.java:83)

Discussion

  • Bat

    Bat - 2007-10-28

    Logged In: YES
    user_id=1683596
    Originator: NO

    Thank you. Change done in v1.1

     
  • Bat

    Bat - 2007-10-28
    • priority: 5 --> 2
     
  • Nobody/Anonymous

    this bug is still there

    --- jbittorrentapi-v1.0/src/jBittorrentAPI/DownloadManager.java 2007-10-25 12:48:50.000000000 +1000
    +++ jbittorrentapi-v1.0/src/jBittorrentAPI/DownloadManager.java 2008-11-20 19:39:52.000000000 +1100
    @@ -68,7 +68,7 @@
    private PeerUpdater pu = null;
    private ConnectionListener cl = null;

    - private List unchokeList = new LinkedList();
    + private LinkedList unchokeList = new LinkedList();

    //private List<Peer> peerList = null;
    private LinkedHashMap<String, Peer> peerList = null;
    @@ -617,7 +617,7 @@
    if (!this.unchokeList.isEmpty()) {
    Peer p = null;
    do {
    - p = (Peer)this.unchokeList.remove(0);
    + p = (Peer)this.unchokeList.remove();
    synchronized (this.task) {
    DownloadTask dt = this.task.get(p.toString());
    if (dt != null) {

    Fixes it for me

     

Log in to post a comment.

MongoDB Logo MongoDB