Skip to content

Divide by zero when extra message is too long on indefinite progress bar #84

Closed

Description

@rharder

I'm using an indefinite progress bar, and if the setExtraMessage() value is too long, ProgressBar throws an Arithmetic exception for a divide by zero. It comes from DefaultProgressBarRenderer line 96:

int pos = (int)(progress.current % length);

An example:

public static void main(String[] args) throws InterruptedException {
    try (ProgressBar pb = new ProgressBar("test", -1)) {
        for (int i = 0; i < 10; i++) {
            pb.step();
            // May differ for your terminal...
            //                 Mine breaks and is "too long" when I get to 38: |
            // (At 37, it breaks when the counter goes double digits)
            pb.setExtraMessage(Paths.get("12345678901234567890123456789012345678").toString());
            TimeUnit.MILLISECONDS.sleep(250);
        }
    }
}

Stack trace looks like this;

Exception in thread "me.tongfei.progressbar.ProgressBar" java.lang.ArithmeticException: / by zero
	at me.tongfei.progressbar.DefaultProgressBarRenderer.render(DefaultProgressBarRenderer.java:96)
	at me.tongfei.progressbar.ProgressThread.refresh(ProgressThread.java:37)
	at me.tongfei.progressbar.ProgressThread.run(ProgressThread.java:48)
	at java.lang.Thread.run(Thread.java:748)

Activity

  1. added a commit that references this issue on Aug 23, 2020
    3b1696b
  2. ctongfei commented on Aug 26, 2020

    @ctongfei
    Owner

    Thanks @rharder for the bug report, and also @AndreiNekrasOn for providing a fix! This will be fixed in the next version.

  3. added this to the 0.9 milestone on Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions