Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9793fcec2efd
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8a59c24d8e11
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 29, 2014

  1. Copy the full SHA
    667c5ff View commit details
  2. Merge pull request #595 from mszukalski/TRUNK-4244

    TRUNK-4244: SonarQube - Method may fail to clean up stream or resource o...
    dkayiwa committed Jan 29, 2014
    Copy the full SHA
    8a59c24 View commit details
14 changes: 12 additions & 2 deletions api/src/main/java/org/openmrs/util/OpenmrsUtil.java
Original file line number Diff line number Diff line change
@@ -329,16 +329,26 @@ public static String getFileAsString(File file) throws IOException {
* @throws IOException
*/
public static byte[] getFileAsBytes(File file) throws IOException {
FileInputStream fileInputStream = null;
try {
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream = new FileInputStream(file);
byte[] b = new byte[fileInputStream.available()];
fileInputStream.read(b);
fileInputStream.close();
return b;
}
catch (Exception e) {
log.error("Unable to get file as byte array", e);
}
finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
}
catch (IOException io) {
log.warn("Couldn't close fileInputStream: " + io);
}
}
}

return null;
}
24 changes: 20 additions & 4 deletions web/src/main/java/org/openmrs/module/web/WebModuleUtil.java
Original file line number Diff line number Diff line change
@@ -132,6 +132,8 @@ public static boolean startModule(Module mod, ServletContext servletContext, boo
// copy the html files into the webapp (from /web/module/ in the module)
// also looks for a spring context file. If found, schedules spring to be restarted
JarFile jarFile = null;
OutputStream outStream = null;
InputStream inStream = null;
try {
File modFile = mod.getFile();
jarFile = new JarFile(modFile);
@@ -180,11 +182,9 @@ public static boolean startModule(Module mod, ServletContext servletContext, boo
// outFile = new File(absPath.replace("/", File.separator) + MODULE_NON_JSP_EXTENSION);

// copy the contents over to the webapp for non directories
OutputStream outStream = new FileOutputStream(outFile, false);
InputStream inStream = jarFile.getInputStream(entry);
outStream = new FileOutputStream(outFile, false);
inStream = jarFile.getInputStream(entry);
OpenmrsUtil.copyFile(inStream, outStream);
inStream.close();
outStream.close();
}
} else if (name.equals("moduleApplicationContext.xml") || name.equals("webModuleApplicationContext.xml")) {
moduleNeedsContextRefresh = true;
@@ -207,6 +207,22 @@ public static boolean startModule(Module mod, ServletContext servletContext, boo
log.warn("Couldn't close jar file: " + jarFile.getName(), io);
}
}
if (inStream != null) {
try {
inStream.close();
}
catch (IOException io) {
log.warn("Couldn't close InputStream: " + io);
}
}
if (outStream != null) {
try {
outStream.close();
}
catch (IOException io) {
log.warn("Couldn't close OutputStream: " + io);
}
}
}

// find and add the dwr code to the dwr-modules.xml file (if defined)
15 changes: 12 additions & 3 deletions web/src/main/java/org/openmrs/web/Listener.java
Original file line number Diff line number Diff line change
@@ -337,17 +337,26 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc
// happen because the servlet container (i.e. tomcat) crashes when first loading this file
log.debug("Error clearing dwr-modules.xml", e);
dwrFile.delete();
FileWriter writer = null;
try {
FileWriter writer = new FileWriter(dwrFile);
writer = new FileWriter(dwrFile);
writer
.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE dwr PUBLIC \"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN\" \"http://directwebremoting.org/schema/dwr20.dtd\">\n<dwr></dwr>");
writer.close();
}
catch (IOException io) {
log.error("Unable to clear out the " + dwrFile.getAbsolutePath()
+ " file. Please redeploy the openmrs war file", io);
}

finally {
if (writer != null) {
try {
writer.close();
}
catch (IOException io) {
log.warn("Couldn't close Writer: " + io);
}
}
}
}
}

14 changes: 12 additions & 2 deletions web/src/main/java/org/openmrs/web/filter/StartupFilter.java
Original file line number Diff line number Diff line change
@@ -123,14 +123,24 @@ public final void doFilter(ServletRequest request, ServletResponse response, Fil
if (httpRequest.getPathInfo() != null)
file = new File(file, httpRequest.getPathInfo());

InputStream imageFileInputStream = null;
try {
InputStream imageFileInputStream = new FileInputStream(file);
imageFileInputStream = new FileInputStream(file);
OpenmrsUtil.copyFile(imageFileInputStream, httpResponse.getOutputStream());
imageFileInputStream.close();
}
catch (FileNotFoundException e) {
log.error("Unable to find file: " + file.getAbsolutePath());
}
finally {
if (imageFileInputStream != null) {
try {
imageFileInputStream.close();
}
catch (IOException io) {
log.warn("Couldn't close imageFileInputStream: " + io);
}
}
}
} else if (servletPath.startsWith("/scripts")) {
log
.error("Calling /scripts during the initializationfilter pages will cause the openmrs_static_context-servlet.xml to initialize too early and cause errors after startup. Use '/initfilter"