Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rharder opened this issue Aug 20, 2020 · 1 comment
Closed
Labels
Milestone

Comments

@rharder
Copy link

rharder commented Aug 20, 2020

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)
@ctongfei
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants