Skip to content

Endless loop when using FastaReader #282

Closed

Description

@andreasprlic

Toorn reported on mailing list that he encountered an endless loop with one of his fasta files. I can reproduce this.

Activity

  1. added this to the BioJava 4.1.0 milestone on Jun 17, 2015
  2. self-assigned this
    on Jun 17, 2015
  3. added 2 commits that reference this issue on Jun 17, 2015
  4. andreasprlic commented on Jun 17, 2015

    @andreasprlic
    MemberAuthor
  5. aalhossary commented on Jun 26, 2015

    @aalhossary
    Member

    Actually there is no bug there. The function documentation never mentioned that a null might be returned.
    The proper way of using the function is

            do {
                b = fastaReader.process(10);
                for (String seq : b.keySet()) {
                    System.out.println(seq);
                }
            } while (b.size() == 10);
    

    It has been there for a while and others may have been using it

    Shall we revert this commit?

  6. andreasprlic commented on Jun 26, 2015

    @andreasprlic
    MemberAuthor

    Please try the test case, it did not work before the patch.

  7. added a commit that references this issue on Jun 27, 2015
  8. aalhossary commented on Jun 27, 2015

    @aalhossary
    Member

    I updated the function and the test case

    There are two different issues here:

    1.  The functions fails because it was designed to never return null at all, that’s why it falls into an infinite loop. Instead it returns a LinkedHashMap with size in the in the range [0, max], where size < max indicates last (probably incomplete) read batch of sequences.
      

    It should not be called within a

    while ((ret = process(int)) != null){/code/}

    loop

    Instead it should be called within a

    do{ret = process(int); /code/} while ( ret.size() < max);

    loop

    1.  If there is a blank line after the last sequence of the last batch, it fails to interpret it as either a new sequence or a closed stream. I corrected this by passing any blank lines, and adding an EOF flag.
      

    P.S. I made a pull request but I am not sure it will catch the new release.

  9. andreasprlic commented on Jan 14, 2016

    @andreasprlic
    MemberAuthor

    not sure why this one is still open, this one got fixed already for last release.

  10. added a commit that references this issue on Jul 3, 2020
    b9f4b81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugBugs and bugfixes

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions