Skip to content

Commit

Permalink
TRUNK-6068: Loading a non-existent advice point should not stop the a…
Browse files Browse the repository at this point in the history
…pplication
  • Loading branch information
ibacher committed Feb 28, 2022
1 parent 5b58ea6 commit 6ec4299
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/org/openmrs/module/AdvicePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AdvicePoint(String point, Class<?> clazz) {
this.classInstance = clazz.newInstance();
}
catch (Exception e) {
log.error("Unable to get instance of: " + clazz.getName(), e);
log.error("Unable to get instance of: [{}]", clazz.getName(), e);
}
}

Expand All @@ -60,8 +60,8 @@ public Object getClassInstance() {
Class<?> c = ModuleFactory.getModuleClassLoader(getModule()).loadClass(getClassName());
o = c.newInstance();
}
catch (Exception e) {
log.warn("Could not get instance for advice point: " + point, e);
catch (Exception | LinkageError e) {
log.warn("Could not get instance for advice point [{}]", point, e);
}
classInstance = o;
return o;
Expand Down
12 changes: 7 additions & 5 deletions api/src/main/java/org/openmrs/module/ModuleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -880,16 +880,18 @@ public static void loadAdvice(Module module) {
try {
cls = Context.loadClass(advice.getPoint());
Object aopObject = advice.getClassInstance();
if (Advisor.class.isInstance(aopObject)) {
log.debug("adding advisor: " + aopObject.getClass());
if (aopObject instanceof Advisor) {
log.debug("adding advisor [{}]", aopObject.getClass());
Context.addAdvisor(cls, (Advisor) aopObject);
} else {
log.debug("Adding advice: " + aopObject.getClass());
} else if (aopObject != null) {
log.debug("adding advice [{}]", aopObject.getClass());
Context.addAdvice(cls, (Advice) aopObject);
} else {
log.debug("Could not load advice class for {} [{}]", advice.getPoint(), advice.getClassName());
}
}
catch (ClassNotFoundException | NoClassDefFoundError e) {
log.warn("Could not load advice point: " + advice.getPoint(), e);
log.warn("Could not load advice point [{}]", advice.getPoint(), e);
}
}
}
Expand Down

0 comments on commit 6ec4299

Please sign in to comment.