我的应用程序使用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。 at 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。 at 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。 at gnu.trove.TPrimitiveHash.capacity(TPrimitiveHash.java:99)
/ / protected int capacity()
/ / {
**/ 99 / return _states.length;**
/ / }
如您所见,这些行不进行任何划分。
那么为什么这些除以零例外被抛出? gnu.trove类中可以抛出这些java.lang.ArithmeticException的场景是什么:在代码中除以零的异常?