#vulnerable code 
                             public static void main(String[] args) throws Exception {
		SearchEngine2 engine = new SearchEngine2();
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String line = null;
		System.out.print("openlegLuceneConsole> ");
		while (!(line = reader.readLine()).equals("quit"))
		{
			if (line.startsWith("index "))
			{
				String cmd = line.substring(line.indexOf(" ")+1);
				StringTokenizer st = new StringTokenizer(cmd);
				String iType = st.nextToken();
				int start = 1;
				int max = 1000000;
				int pageSize = 10;
				
				if (st.hasMoreTokens())
					start = Integer.parseInt(st.nextToken());
				
				if (st.hasMoreTokens())
					max = Integer.parseInt(st.nextToken());
				
				if (st.hasMoreTokens())
					pageSize = Integer.parseInt(st.nextToken());
				
				engine.indexSenateData(iType, start, max, pageSize,
						new LuceneSerializer[]{new XmlSerializer(), new JsonSerializer()});
			}
			else if (line.startsWith("optimize"))
				engine.optimize();
			else if (line.startsWith("delete"))
			{
				StringTokenizer cmd = new StringTokenizer(line.substring(line.indexOf(" ")+1)," ");
				String type = cmd.nextToken();
				String id = cmd.nextToken();
				engine.deleteSenateObjectById(type, id);
			}
			else if (line.startsWith("create"))
				engine.createIndex();
			else
				engine.search(line, "xml", 1, 10, null, false);
			
			System.out.print("openleg search > ");
		}
		System.out.println("Exiting Search Engine");
	} 
                            #location 30 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                             public static void main(String[] args) throws Exception {
		SearchEngine2 engine = SearchEngine2.getInstance();
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String line = null;
		System.out.print("openlegLuceneConsole> ");
		while (!(line = reader.readLine()).equals("quit"))
		{
			if (line.startsWith("index "))
			{
				String cmd = line.substring(line.indexOf(" ")+1);
				StringTokenizer st = new StringTokenizer(cmd);
				String iType = st.nextToken();
				int start = 1;
				int max = 1000000;
				int pageSize = 10;
				
				if (st.hasMoreTokens())
					start = Integer.parseInt(st.nextToken());
				
				if (st.hasMoreTokens())
					max = Integer.parseInt(st.nextToken());
				
				if (st.hasMoreTokens())
					pageSize = Integer.parseInt(st.nextToken());
				
				engine.indexSenateData(iType, start, max, pageSize,
						new LuceneSerializer[]{new XmlSerializer(), new JsonSerializer()});
			}
			else if (line.startsWith("optimize"))
				engine.optimize();
			else if (line.startsWith("delete"))
			{
				StringTokenizer cmd = new StringTokenizer(line.substring(line.indexOf(" ")+1)," ");
				String type = cmd.nextToken();
				String id = cmd.nextToken();
				engine.deleteSenateObjectById(type, id);
			}
			else if (line.startsWith("create"))
				engine.createIndex();
			else
				engine.search(line, "xml", 1, 10, null, false);
			
			System.out.print("openleg search > ");
		}
		System.out.println("Exiting Search Engine");
	}