Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/metron/pull/985#discussion_r180583454
--- Diff:
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/resolver/ClasspathFunctionResolver.java
---
@@ -254,18 +266,24 @@ public void initialize(Context context) {
Set<String> classes = new HashSet<>();
Set<Class<? extends StellarFunction>> ret = new HashSet<>();
for(ClassLoader cl : cls) {
- for(Class<?> c : ClassIndex.getAnnotated(Stellar.class, cl)) {
- LOG.debug("{}: Found class: {}", cl.getClass().getCanonicalName(),
c.getCanonicalName());
- boolean isAssignable = StellarFunction.class.isAssignableFrom(c);
- boolean isFiltered = filterBuilder.apply(c.getCanonicalName());
- if( isAssignable && isFiltered ) {
- String className = c.getName();
- if(!classes.contains(className)) {
- LOG.debug("{}: Added class: {}",
cl.getClass().getCanonicalName(), className);
- ret.add((Class<? extends StellarFunction>) c);
- classes.add(className);
+ for(Class<?> c : getStellarClasses(cl)) {
+ try {
+ LOG.debug("{}: Found class: {}",
cl.getClass().getCanonicalName(), c.getCanonicalName());
+ if (includeClass(c, filterBuilder)) {
+ String className = c.getName();
+ if (!classes.contains(className)) {
+ LOG.debug("{}: Added class: {}",
cl.getClass().getCanonicalName(), className);
+ ret.add((Class<? extends StellarFunction>) c);
+ classes.add(className);
+ }
}
}
+ catch(Error le) {
+ //we have had some error loading a stellar function. This could
mean that
+ //the classpath is unstable (e.g. old copies of jars are on the
classpath).
+ LOG.error("Skipping class: " + le.getMessage()
--- End diff --
Commons has a method that handles this situation well. I tend to always
use that in these situations; `ClassUtils.getCanonicalName(Class<?> cls,
String valueIfNull)`. If I'm not mistaken, it would make your logic simpler;
only one error log statement.
---