0
 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.

TofuBeer
61.6k18 gold badges120 silver badges163 bronze badges
asked Mar 15, 2013 at 18:38
2
  • 2
    What are the declared and/or run time types of these variables? Commented 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 class Commented Mar 15, 2013 at 18:43

2 Answers 2

3

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?

answered Mar 15, 2013 at 18:45
Sign up to request clarification or add additional context in comments.

1 Comment

I think this is the most likely explanation (+1)
1

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?

answered Mar 15, 2013 at 18:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.