//Target Program which gives NPE - Anushri
package boomerang.example;
import java.util.Random;
public class BoomerangExampleTarget3 {

	public static class Dummy {  
	    // Dummy method  
		Dummy f;
	    public void sayHello() {  
	        System.out.println("Hello from Dummy!");  
	    }  
	}  
	public static void main(String[] args) {

        withNPE();
    }
	public static void withNPE()
	{
      /*  // Step 1: Create a Dummy object  
        Dummy y = null; // new Dummy(); // null;  
        Dummy z;  
        Dummy x = new Dummy(); 
        // Step 2: Assign references 
        Random random = new Random();  
		int value = random.nextInt(2); // Returns 0 or 1 
		if (value == 0)
		{
			z=y;
			x=z;
		}
//		else
//		{
//			x = new Dummy(); //new Person(3);
//		}

         
  
        // Step 3: Access method using x  
//        x.sayHello(); // Output: Hello from Dummy! 
        System.out.println(x.f); */
		
		
     // Step 1: Create a Dummy object  
        Dummy y = new Dummy(); // null;  
        Dummy z = new Dummy();  
//        Dummy x = new Dummy(); 
        // Step 2: Assign references 
        Random random = new Random();  
		int value = random.nextInt(2); // Returns 0 or 1 
		if (value == 0)
		{
			y.f=z.f;
			z.f=null;
		}
//		else
//		{
//			x = new Dummy(); //new Person(3);
//		}

         
		Dummy x = z.f;
        // Step 3: Access method using x  
//        x.sayHello(); // Output: Hello from Dummy! 
        System.out.println(x.f);
    }  
}
