System.out.println(symbol_b.symbolName + " " + symbol_b.pointsTo.size());
// change the fieldpointsTo set of all above symbols
for (int i = 0; i < samePointsTo.size(); i++)
{
for (int j = 0; j < samePointsTo.elementAt(i).size(); j++)
{
Symbol symbol = samePointsTo.elementAt(i).elementAt(j);
System.out.println(symbol.symbolName);
// if field information is already present
if (symbol.fieldPointsTo.containsKey(fieldObj))
{
symbol.fieldPointsTo.get(fieldObj).clear();
symbol.fieldPointsTo.get(fieldObj).addAll(symbol_b.pointsTo);
}
else
{
// we have to create field information
symbol.fieldPointsTo.put(fieldObj, symbol_b.pointsTo);
}
}
}
System.out.println(symbol_b.symbolName + " " + symbol_b.pointsTo.size());
Before the for loop the size of symbol_b.pointsTo is 2, but just after the for loop its value is changed from 2 to 0. How it is happening can anyone tell me. I am not doing anything to symbol_b.pointsTo and symbol_b.pointsTo is a vetor.
-
2What are the declared and/or run time types of these variables?Richard JP Le Guen– Richard JP Le Guen2013年03月15日 18:41:17 +00:00Commented Mar 15, 2013 at 18:41
-
fieldPointsTo is a hashTable, pointsTo is a vector, and symbol,symbol_a, symbol_b is of type Symbol which is a user defined classneel– neel2013年03月15日 18:43:43 +00:00Commented Mar 15, 2013 at 18:43
2 Answers 2
Perhaps pointsTo is not only referred to by that variable name, but is also a value returned by symbol.fieldPointsTo.get(fieldObj), so that when you call .clear() on that, it removes all the vector's elements?
1 Comment
Could it be the case that:
if (symbol.fieldPointsTo.containsKey(fieldObj))
{
symbol.fieldPointsTo.get(fieldObj).clear();
symbol.fieldPointsTo.get(fieldObj).addAll(symbol_b.pointsTo);
}
the symbol variable points to symbol_b, symbol_b is not in the fieldPointsTo so it calls clear() on it?