CS/SWE 332 In Class Exercise Number 1

Name(s):
Instructions: Work with your neighbors in groups. This exercise touches on some subtle issues in data abstraction, program correctness, and security. Despite the simplicity of the code, there is a lot going on in this example. Hence don't worry if it seems confusing today. We'll revisit the topics in this example at various times over the course of the semester.
Set<List<String>> s = new HashSet<List<String>>();     // s = ____
List<String> x = new ArrayList<String>();  // x = ____
List<String> y = new ArrayList<String>();  // y = ____

s.add(x);		 // s = ____
s.add(y);		 // s = ____

s.contains(y)            // well defined?  true or false?

y.add("cat");	         // y = ____
                         // s = ____

s.contains(y);           // well defined?  true or false?

s.add(y);		 // s = _____

y.remove("cat");	 // y = _____
                         // s = _____

s.remove(y);		 // s = _____

s.contains(y);           // well defined?  true or false?
s.contains(x);           // well defined?  true or false?
  1. What does this sequence have to do with with the equals() method? How do you know? Be as precise as you can. Ideally, point to a web page to justify your answer.

  2. Fill in the values.

  3. There is a problem. Describe the problem using as general a theory as you can.

  4. Whose responsibility is it to avoid this problem? In general, is this a good thing, or a bad thing?

  5. Might anyone ever cause this problem to occur deliberately? Why or why not?