Skip to content

Commit

Permalink
Fix a memory leak an re-use the moduleClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher committed Jun 24, 2022
1 parent 9d41ee2 commit a35a67b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions api/src/main/java/org/openmrs/module/ModuleFactory.java
Expand Up @@ -976,22 +976,30 @@ private static void runDiff(Module module, String version, String sql) {
* @param module the module being executed on
*/
private static void runLiquibase(Module module) {
ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(module);
InputStream inStream = moduleClassLoader.getResourceAsStream(MODULE_CHANGELOG_FILENAME);
boolean liquibaseFileExists = (inStream != null);
ModuleClassLoader moduleClassLoader = getModuleClassLoader(module);
boolean liquibaseFileExists = false;

if (moduleClassLoader != null) {
try (InputStream inStream = moduleClassLoader.getResourceAsStream(MODULE_CHANGELOG_FILENAME)) {
liquibaseFileExists = (inStream != null);
}
catch (IOException ignored) {

}
}

if (liquibaseFileExists) {
try {
// run liquibase.xml by Liquibase API
DatabaseUpdater.executeChangelog(MODULE_CHANGELOG_FILENAME, new Contexts(), null,
getModuleClassLoader(module));
DatabaseUpdater.executeChangelog(MODULE_CHANGELOG_FILENAME, new Contexts(), null, moduleClassLoader);
}
catch (InputRequiredException ire) {
catch (InputRequiredException e) {
// the user would be stepped through the questions returned here.
throw new ModuleException("Input during database updates is not yet implemented.", module.getName(), ire);
throw new ModuleException("Input during database updates is not yet implemented.", module.getName(), e);
}
catch (Exception e) {
throw new ModuleException("Unable to update data model using liquibase.xml.", module.getName(), e);
throw new ModuleException("Unable to update data model using " + MODULE_CHANGELOG_FILENAME + ".",
module.getName(), e);
}
}
}
Expand Down

0 comments on commit a35a67b

Please sign in to comment.