#vulnerable code 
                             @Test
	public void subTypes() throws Exception {
		VCard vcard = new VCard();

		//one sub type
		AddressType adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		vcard.addAddress(adr);

		//two types
		adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		adr.getSubTypes().put("LANGUAGE", "FR");
		adr.getSubTypes().put("LANGUAGE", "es");
		vcard.addAddress(adr);

		//three types
		//make sure it properly escapes sub type values that have special chars
		adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		adr.getSubTypes().put("LANGUAGE", "FR");
		adr.getSubTypes().put("LANGUAGE", "es");
		adr.getSubTypes().put("TEXT", "123 \"Main\" St\r\nAustin, ;TX; 12345");
		vcard.addAddress(adr);

		//2.1
		StringWriter sw = new StringWriter();
		VCardWriter vcw = new VCardWriter(sw, VCardVersion.V2_1, null);
		vcw.setAddProdId(false);
		vcw.write(vcard);
		String actual = sw.toString();

		StringBuilder sb = new StringBuilder();
		sb.append("BEGIN:VCARD\r\n");
		sb.append("VERSION:2.1\r\n");
		sb.append("ADR;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR;LANGUAGE=es;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR;LANGUAGE=es;TEXT=\"123 \\\"Main\\\" St\\nAustin, ;TX; 12345\";X-DOORMAN=true:;;;;;;\r\n");
		sb.append("END:VCARD\r\n");
		String expected = sb.toString();

		assertEquals(expected, actual);

		//3.0
		sw = new StringWriter();
		vcw = new VCardWriter(sw, VCardVersion.V3_0, null);
		vcw.setAddProdId(false);
		vcw.write(vcard);
		actual = sw.toString();

		sb = new StringBuilder();
		sb.append("BEGIN:VCARD\r\n");
		sb.append("VERSION:3.0\r\n");
		sb.append("ADR;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR,es;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR,es;TEXT=\"123 \\\"Main\\\" St\\nAustin, ;TX; 12345\";X-DOORMAN=true:;;;;;;\r\n");
		sb.append("END:VCARD\r\n");
		expected = sb.toString();

		assertEquals(expected, actual);
	} 
                            #location 30 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                             @Test
	public void subTypes() throws Exception {
		VCard vcard = new VCard();

		//one sub type
		AddressType adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		vcard.addAddress(adr);

		//two types
		adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		adr.getSubTypes().put("LANGUAGE", "FR");
		adr.getSubTypes().put("LANGUAGE", "es");
		vcard.addAddress(adr);

		//three types
		//make sure it properly escapes sub type values that have special chars
		adr = new AddressType();
		adr.getSubTypes().put("X-DOORMAN", "true");
		adr.getSubTypes().put("LANGUAGE", "FR");
		adr.getSubTypes().put("LANGUAGE", "es");
		adr.getSubTypes().put("TEXT", "123 \"Main\" St\r\nAustin, ;TX; 12345");
		vcard.addAddress(adr);

		//2.1
		StringWriter sw = new StringWriter();
		VCardWriter vcw = new VCardWriter(sw, VCardVersion.V2_1, null, "\r\n");
		vcw.setAddProdId(false);
		vcw.write(vcard);
		String actual = sw.toString();

		StringBuilder sb = new StringBuilder();
		sb.append("BEGIN:VCARD\r\n");
		sb.append("VERSION:2.1\r\n");
		sb.append("ADR;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR;LANGUAGE=es;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR;LANGUAGE=es;TEXT=\"123 \\\"Main\\\" St\\nAustin, ;TX; 12345\";X-DOORMAN=true:;;;;;;\r\n");
		sb.append("END:VCARD\r\n");
		String expected = sb.toString();

		assertEquals(expected, actual);

		//3.0
		sw = new StringWriter();
		vcw = new VCardWriter(sw, VCardVersion.V3_0, null, "\r\n");
		vcw.setAddProdId(false);
		vcw.write(vcard);
		actual = sw.toString();

		sb = new StringBuilder();
		sb.append("BEGIN:VCARD\r\n");
		sb.append("VERSION:3.0\r\n");
		sb.append("ADR;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR,es;X-DOORMAN=true:;;;;;;\r\n");
		sb.append("ADR;LANGUAGE=FR,es;TEXT=\"123 \\\"Main\\\" St\\nAustin, ;TX; 12345\";X-DOORMAN=true:;;;;;;\r\n");
		sb.append("END:VCARD\r\n");
		expected = sb.toString();

		assertEquals(expected, actual);
	}