我的应用程序使用 gnu.trove 2.0.3 版。最近它在 gnu.trove 库代码的不同区域抛出除以零异常
例如:1。
java.lang.ArithmeticException: divide by zero
at gnu.trove.TIntHash.index(TIntHash.java:201)
at gnu.trove.TIntObjectHashMap.get(TIntObjectHashMap.java:204)
2.
java.lang.ArithmeticException: divide by zero
at gnu.trove.TIntHash.insertionIndex(TIntHash.
at gnu.trove.TIntObjectHashMap.put(TIntObjectHashMap.java:153)
3.
java.lang.ArithmeticException: divide by zero
at gnu.trove.TPrimitiveHash.capacity(TPrimitiveHash.java:99)
at gnu.trove.THash.postInsertHook(THash.java:358)
at gnu.trove.TIntLongHashMap.put(TIntLongHashMap.java:165)
这是在一种情况下引发除以零异常的应用程序代码片段:
TIntLongHashMap testMap = new TIntLongHashMap();
TIntLongHashMap test1Map = new TIntLongHashMap();
.
.
.
TIntLongIterator iter = test1Map.iterator();
for (int i = test1Map.size(); i-- > 0; )
{
iter.advance();
**testMap.put(iter.key(), iter.value());**
}
从堆栈跟踪中,我查看了在这些库类中引发这些异常的代码行: 1. 在 gnu.trove.TIntHash.index(TIntHash.java:201)
protected int index(int val)
/ / {
/ 185 / byte[] states = _states;
/ 186 / int[] set = _set;
/ 187 / int length = states.length;
/ 188 / int hash = _hashingStrategy.computeHashCode(val) & 0x7FFFFFFF;
/ 189 / int index = hash % length;
/ /
/ 191 / if ((states[index] != 0) && ((states[index] == 2) || (set[index] != val)))
/ / {
/ /
/ 194 / int probe = 1 + hash % (length - 2);
/ / do
/ / {
/ 197 / index -= probe;
/ 198 / if (index < 0) {
/ 199 / index += length;
/ / }
**/ 201 / } while ((states[index] != 0) && ((states[index] == 2) || (set[index] != val)))**;
/ / }
/ /
/ /
/ 205 / return states[index] == 0 ? -1 : index;
/ / }
2. 在 gnu.trove.TIntHash.insertionIndex(TIntHash.java:271 )
protected int insertionIndex(int val)
/ / {
byte[] states = _states;
/ 220 / int[] set = _set;
/ 221 / int length = states.length;
/ 222 / int hash = _hashingStrategy.computeHashCode(val) & 0x7FFFFFFF;
/ 223 / int index = hash % length;
/ /
/ 225 / if (states[index] == 0)
/ 226 / return index;
/ 227 / if ((states[index] == 1) && (set[index] == val)) {
/ 228 / return -index - 1;
/ / }
/ /
/ 231 / int probe = 1 + hash % (length - 2);
/ 245 / if (states[index] != 2)
/ / {
/ / do
/ / {
/ 249 / index -= probe;
/ 250 / if (index < 0) {
/ 251 / index += length;
/ / }
/ 253 / } while ((states[index] == 1) && (set[index] != val));
/ / }
/ /
/ /
/ /
/ /
/ 259 / if (states[index] == 2) {
/ 260 / int firstRemoved = index;
/ 261 / while ((states[index] != 0) && ((states[index] == 2) || (set[index] != val)))
/ / {
/ 263 / index -= probe;
/ 264 / if (index < 0) {
/ 265 / index += length;
/ / }
/ / }
/ 268 / return states[index] == 1 ? -index - 1 : firstRemoved;
/ / }
/ /
/ **271 / return states[index] == 1 ? -index - 1 : index;
/ / }**
3. 在 gnu.trove.TPrimitiveHash.capacity(TPrimitiveHash.java:99)
/ / protected int capacity()
/ / {
**/ 99 / return _states.length;**
/ / }
如您所见,这些行不做任何划分。
那么为什么会抛出这些除以零的异常呢?gnu.trove 类中的哪些场景可以抛出这些 java.lang.ArithmeticException:代码中除以零异常?