diff --git a/org.adempiere.base/src/org/compiere/impexp/OFXBankStatementHandler.java b/org.adempiere.base/src/org/compiere/impexp/OFXBankStatementHandler.java index a2df756ddd..513f2ba67f 100644 --- a/org.adempiere.base/src/org/compiere/impexp/OFXBankStatementHandler.java +++ b/org.adempiere.base/src/org/compiere/impexp/OFXBankStatementHandler.java @@ -202,6 +202,10 @@ public abstract class OFXBankStatementHandler extends DefaultHandler m_errorMessage = new StringBuffer("ErrorInitializingParser"); m_errorDescription = new StringBuffer("Unable to initialize SAX parser: ").append(e.getMessage()); } + + if (!result) + closeBufferedReader(); + return result; } // init @@ -256,6 +260,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler { m_errorMessage = new StringBuffer("ErrorReadingData"); m_errorDescription = new StringBuffer(e.getMessage()); + closeBufferedReader(); return result; } @@ -322,11 +327,22 @@ public abstract class OFXBankStatementHandler extends DefaultHandler { m_errorMessage = new StringBuffer("ErrorReadingData"); m_errorDescription = new StringBuffer(e.getMessage()); + } finally { + closeBufferedReader(); } return result; } // loadLines + private void closeBufferedReader() { + if (m_reader != null) + try { + m_reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Method getDateLastRun * @return Timestamp diff --git a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java index 7f2b1aedf4..96e3221e9e 100644 --- a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java +++ b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java @@ -17,7 +17,6 @@ package org.compiere.impexp; import java.io.FileInputStream; -import java.io.IOException; import org.compiere.model.MBankStatementLoader; import org.xml.sax.SAXException; @@ -38,6 +37,9 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im * @return boolean * @see org.compiere.impexp.BankStatementLoaderInterface#init(MBankStatementLoader) */ + //m_stream is not closed because the BufferedReader in the parent class is closed and according to the Java docs: + //Calling close() on the BufferedReader closes the underlying stream by default implementation + @SuppressWarnings("resource") public boolean init(MBankStatementLoader controller) { boolean result = false; @@ -72,13 +74,6 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im { m_errorMessage = new StringBuffer("ErrorReadingData"); m_errorDescription = new StringBuffer(); - }finally{ - if (m_stream != null) - try { - m_stream.close(); - } catch (IOException e) { - e.printStackTrace(); - } } return result;