You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Divide by zero when extra message is too long on indefinite progress bar #84
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
resolve ctongfei#84
ctongfei commentedon Aug 26, 2020
Thanks @rharder for the bug report, and also @AndreiNekrasOn for providing a fix! This will be fixed in the next version.