IDEMPIERE-455 Discover and fix FindBugs problems / Pattern OS_OPEN_STREAM

This commit is contained in:
Richard Morales 2012-12-11 16:48:34 -05:00
parent db87b54563
commit d9afbe2768
12 changed files with 117 additions and 14 deletions

View File

@ -39,8 +39,10 @@ public class ExtensionPriorityManager {
URL url = location.getURL();
File file = new File(url.getPath(), "extensions-priorty.properties");
if (file.exists() && file.canRead()) {
FileInputStream fileInput = null;
try {
priorityMap.load(new FileInputStream(file));
fileInput = new FileInputStream(file);
priorityMap.load(fileInput);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -48,6 +50,15 @@ public class ExtensionPriorityManager {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if (fileInput != null) {
try {
fileInput.close();
} catch (Exception e2) {}
fileInput = null;
}
}
}
}

View File

@ -37,6 +37,7 @@ public class RestletUtil {
*/
@SuppressWarnings("unchecked")
public static <T> T toObject(Representation entity) {
ObjectInputStream ois = null;
try {
if (entity instanceof WrapperRepresentation) {
entity = ((WrapperRepresentation)entity).getWrappedRepresentation();
@ -46,7 +47,7 @@ public class RestletUtil {
return (T) or.getObject();
} else if (entity instanceof InputRepresentation) {
InputRepresentation ir = (InputRepresentation) entity;
ObjectInputStream ois = new ObjectInputStream(ir.getStream());
ois = new ObjectInputStream(ir.getStream());
return (T) ois.readObject();
} else {
return null;
@ -55,5 +56,13 @@ public class RestletUtil {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
finally{
if (ois != null) {
try {
ois.close();
} catch (Exception e2) {}
ois = null;
}
}
}
}

View File

@ -145,6 +145,7 @@ public class CacheHandler {
private void runURLRequest(String cache, String ID) {
String thisURL = null;
for(int i=0; i<cacheURLs.length; i++) {
try {
thisURL = "http://" + cacheURLs[i] + "/cache/Service?Cache=" + cache + "&ID=" + ID;
URL url = new URL(thisURL);
@ -153,18 +154,26 @@ public class CacheHandler {
URLConnection urlConn = url.openConnection(thisProxy);
urlConn.setUseCaches(false);
urlConn.connect();
Reader stream = new java.io.InputStreamReader(
urlConn.getInputStream());
Reader stream = null;
StringBuilder srvOutput = new StringBuilder();
try {
stream = new java.io.InputStreamReader(urlConn.getInputStream());
int c;
while ( (c=stream.read()) != -1 )
srvOutput.append( (char)c );
} catch (Exception E2) {
E2.printStackTrace();
}
}
finally{
if (stream != null) {
try {
stream.close();
} catch (Exception e) {}
stream = null;
}
}
} catch (IOException E) {
if (log!=null)
log.warning("Can't clean cache at:" + thisURL + " be carefull, your deployment server may use invalid or old cache data!");

View File

@ -244,6 +244,14 @@ public class MPasswordRule extends X_AD_PasswordRule {
} catch (Exception e) {
props = null;
}
finally{
if (in != null) {
try {
in.close();
} catch (Exception e2) {}
in = null;
}
}
if (props == null)
return new MessageResolver();
else

View File

@ -36,9 +36,10 @@ public class StoredHtmlSrc extends MultiPartElement implements Printable {
return;
}
InputStreamReader ins;
BufferedReader bufferedReader = null;
try {
ins = new InputStreamReader(url.openStream());
BufferedReader bufferedReader = new BufferedReader( ins );
bufferedReader = new BufferedReader( ins );
String cssLine;
String result="";
while ((cssLine = bufferedReader.readLine()) != null)
@ -47,5 +48,13 @@ public class StoredHtmlSrc extends MultiPartElement implements Printable {
} catch (IOException e1) {
log.warning("failed to load html-src: " + srcLocation);
}
finally{
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {}
bufferedReader = null;
}
}
}
}

View File

@ -162,6 +162,14 @@ public class KeyStoreMgt
log.log(Level.SEVERE, "load", e);
return null;
}
finally{
if (is != null) {
try {
is.close();
} catch (Exception e2) {}
is = null;
}
}
m_keyStore.load(is, m_password);
}
else

View File

@ -196,10 +196,10 @@ public class PackIn {
byte[] data = null;
File file = new File(m_packageDirectory+File.separator+"blobs"+File.separator, fileName);
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
int b = bis.read();
@ -215,6 +215,12 @@ public class PackIn {
fis.close();
} catch (IOException e) {}
}
if (bis != null) {
try {
bis.close();
} catch (Exception e) {}
bis = null;
}
}
return data;
}

View File

@ -101,8 +101,9 @@ public class Zipper {
}
static public String getParentDir(File zipFilepath)
{
ZipFile zipFile = null;
try {
ZipFile zipFile = new ZipFile(zipFilepath);
zipFile = new ZipFile(zipFilepath);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry = entries.nextElement();
File tempfile = new File(entry.getName());
@ -114,6 +115,14 @@ public class Zipper {
ioe.printStackTrace();
return "";
}
finally{
if (zipFile != null) {
try {
zipFile.close();
} catch (Exception e) {}
zipFile = null;
}
}
}
}// CreateZipFile

View File

@ -75,11 +75,12 @@ public class AdempiereActivator implements BundleActivator {
URL packout = context.getBundle().getEntry("/META-INF/2Pack.zip");
if (packout != null) {
IDictionaryService service = Service.locator().locate(IDictionaryService.class).getService();
FileOutputStream zipstream = null;
try {
// copy the resource to a temporary file to process it with 2pack
InputStream stream = context.getBundle().getEntry("/META-INF/2Pack.zip").openStream();
File zipfile = File.createTempFile(getName(), ".zip");
FileOutputStream zipstream = new FileOutputStream(zipfile);
zipstream = new FileOutputStream(zipfile);
byte[] buffer = new byte[1024];
int read;
while((read = stream.read(buffer)) != -1){
@ -90,6 +91,13 @@ public class AdempiereActivator implements BundleActivator {
} catch (Exception e) {
logger.log(Level.SEVERE, "Error on Dictionary service", e);
}
finally{
if (zipstream != null) {
try {
zipstream.close();
} catch (Exception e2) {}
}
}
}
}

View File

@ -114,9 +114,10 @@ public class HtmlDashboard extends JPanel implements MouseListener,
URL url = getClass().getClassLoader().
getResource("org/compiere/css/PAPanel.css");
InputStreamReader ins;
BufferedReader bufferedReader = null;
try {
ins = new InputStreamReader(url.openStream());
BufferedReader bufferedReader = new BufferedReader( ins );
bufferedReader = new BufferedReader( ins );
String cssLine;
result.append("<style type=\"text/css\">");
while ((cssLine = bufferedReader.readLine()) != null)
@ -125,6 +126,14 @@ public class HtmlDashboard extends JPanel implements MouseListener,
} catch (IOException e1) {
log.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
}
finally{
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception e) {}
bufferedReader = null;
}
}
//System.out.println(result);
switch (requestPage) {
case PAGE_LOGO:

View File

@ -210,9 +210,10 @@ public class DashboardController implements EventListener<Event> {
URL url = getClass().getClassLoader().getResource("org/compiere/css/PAPanel.css");
InputStreamReader ins;
BufferedReader bufferedReader = null;
try {
ins = new InputStreamReader(url.openStream());
BufferedReader bufferedReader = new BufferedReader( ins );
bufferedReader = new BufferedReader( ins );
String cssLine;
result.append("<style type=\"text/css\">");
while ((cssLine = bufferedReader.readLine()) != null)
@ -221,7 +222,14 @@ public class DashboardController implements EventListener<Event> {
} catch (Exception e1) {
logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
}
finally{
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception e) {}
bufferedReader = null;
}
}
result.append("</head><body><div class=\"content\">\n");
// if(description != null)

View File

@ -207,9 +207,10 @@ public class ConfigOracle implements IDatabaseConfig
log.fine(tnsnames);
StringBuffer sb = new StringBuffer();
FileReader fr = null;
try
{
FileReader fr = new FileReader (tnsfile);
fr = new FileReader (tnsfile);
int c;
while ((c = fr.read()) != -1)
sb.append((char)c);
@ -220,6 +221,14 @@ public class ConfigOracle implements IDatabaseConfig
ex.printStackTrace();
return null;
}
finally{
if (fr != null) {
try {
fr.close();
} catch (Exception e) {}
fr = null;
}
}
if (sb.length() == 0)
return null;
return sb;