#vulnerable code 
                                public void testAlternateDefaultEncoding(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String alternateEnc)
            throws Exception {
        try {
            final InputStream is;
            if (prologEnc == null) {
                is = getXmlStream(bomEnc, XML1, streamEnc, prologEnc);
            } else {
                is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
            }
            XmlReader.setDefaultEncoding(alternateEnc);
            final XmlReader xmlReader = new XmlReader(is, cT, false);
            if (!streamEnc.equals("UTF-16")) {
                // we can not assert things here becuase UTF-8, US-ASCII and
                // ISO-8859-1 look alike for the chars used for detection
            } else {
                final String enc;
                if (alternateEnc != null) {
                    enc = alternateEnc;
                } else {
                    enc = streamEnc;
                }
                assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
            }
        } finally {
            XmlReader.setDefaultEncoding(null);
        }
    } 
                            #location 12 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                public void testAlternateDefaultEncoding(final String cT, final String bomEnc, final String streamEnc, final String prologEnc, final String alternateEnc)
            throws Exception {
        XmlReader xmlReader = null;
        try {
            final InputStream is;
            if (prologEnc == null) {
                is = getXmlStream(bomEnc, XML1, streamEnc, prologEnc);
            } else {
                is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
            }
            XmlReader.setDefaultEncoding(alternateEnc);
            xmlReader = new XmlReader(is, cT, false);
            if (!streamEnc.equals("UTF-16")) {
                // we can not assert things here becuase UTF-8, US-ASCII and
                // ISO-8859-1 look alike for the chars used for detection
            } else {
                assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
            }
        } finally {
            XmlReader.setDefaultEncoding(null);
            if (xmlReader != null) {
                xmlReader.close();
            }
        }
    }