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

运行测试类testGenerateId方法java.lang.ArithmeticException: Division by zero #3

Open
wuzhenwei0419 opened this issue Jan 3, 2020 · 0 comments

Comments

@wuzhenwei0419
Copy link

`java.lang.ArithmeticException: Division by zero

at java.math.BigDecimal.divide(BigDecimal.java:1742)
at java.math.BigDecimal.divideToIntegralValue(BigDecimal.java:1792)
at java.math.BigDecimal.divideAndRemainder(BigDecimal.java:1948)
at com.snowalker.shardingjdbc.snowalker.demo.complex.sharding.util.StringUtil.getDbIndexByMod(StringUtil.java:103)
at com.snowalker.shardingjdbc.snowalker.demo.complex.sharding.sequence.KeyGenerator.getDbIndexAndTbIndexMap(KeyGenerator.java:82)
at com.snowalker.shardingjdbc.snowalker.demo.complex.sharding.sequence.KeyGenerator.generateKey(KeyGenerator.java:51)
at com.snowalker.shardingjdbc.snowalker.demo.SnowalkerShardingjdbcDemoApplicationTests.testGenerateId(SnowalkerShardingjdbcDemoApplicationTests.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)`

错误断点
public static long getDbIndexByMod(Object obj,int dbCount,int tbCount) { long tbRange = getModValue(obj, tbCount); BigDecimal bc = new BigDecimal(tbRange); // ==这个位置dbCount/tbCount--> 4/16=0 BigDecimal[] results = bc.divideAndRemainder(new BigDecimal(dbCount/tbCount)); return (long)results[0].intValue(); }

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

No branches or pull requests

1 participant