You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by cestella <gi...@git.apache.org> on 2018/04/09 16:41:18 UTC

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

GitHub user cestella opened a pull request:

    https://github.com/apache/metron/pull/985

    METRON-1515: Errors loading stellar functions currently bomb the entire topology, they should be recoverable

    ## Contributor Comments
    If a bad stellar function gets on the classpath, the entire enrichment topology (or shell) bombs.  We should just log an error and skip the function.
    
    
    ## Pull Request Checklist
    
    Thank you for submitting a contribution to Apache Metron.  
    Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.  
    Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) for complete smoke testing guides.  
    
    
    In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:
    
    ### For all changes:
    - [ ] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
    - [ ] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    
    ### For code changes:
    - [ ] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
    - [ ] Have you included steps or a guide to how the change may be verified and tested manually?
    - [ ] Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:
      ```
      mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
      ```
    
    - [ ] Have you written or updated unit tests and or integration tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
    - [ ] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`:
    
      ```
      cd site-book
      mvn site
      ```
    
    #### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
    It is also recommended that [travis-ci](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cestella/incubator-metron linkageerror

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metron/pull/985.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #985
    
----
commit edffc14335c331fecbe2f3f7133171701c80974c
Author: cstella <ce...@...>
Date:   2018-04-09T16:39:13Z

    METRON-1515: Errors loading stellar functions currently bomb the entire topology, they should be recoverable

----


---

[GitHub] metron issue #985: METRON-1515: Errors loading stellar functions currently b...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/985
  
    @ottobackwards I'm still contemplating that one ;)


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180755523
  
    --- 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 --
    
    We use commons-lang <= [2.6](http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/ClassUtils.html), which does not have that method.  I'd prefer to not update as part of this PR as it seems to me to be an overreach from a risk perspective.


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180576221
  
    --- 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 --
    
    The exception message might not always contain the class name.  We should explicitly log the class name, like we do in the debug statement on line 271.


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180576511
  
    --- 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 --
    
    Yeah, this is tricky, getting the classname may actually cause the exception (this is precisely the scenario that motivated this, sadly).  That's why I forewent that approach.


---

[GitHub] metron issue #985: METRON-1515: Errors loading stellar functions currently b...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/985
  
    +1 by inspection.  Thanks for the contribution!


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180578439
  
    --- 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 --
    
    On second thought, I think I might've squared the circle there in the latest commit.  How do you like what I came up with?


---

[GitHub] metron issue #985: METRON-1515: Errors loading stellar functions currently b...

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/metron/pull/985
  
    +1 LGTM


---

[GitHub] metron issue #985: METRON-1515: Errors loading stellar functions currently b...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/985
  
    Ok, I added a unit test for this as requested.


---

[GitHub] metron issue #985: METRON-1515: Errors loading stellar functions currently b...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/985
  
    Is there a way to test this in the unit tests?


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/metron/pull/985


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by nickwallen <gi...@git.apache.org>.
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.  


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180748583
  
    --- 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 --
    
    I can certainly use `ClassUtils.getCanonicalName` rather than `Class.getName()`, but I would still feel more comfortable with the 2nd try/catch as I cannot guarantee that ClassUtils won't throw an Error in the case of a malformed class on the classpath.  Am I missing any guarantees offered by ClassUtils here?


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180753753
  
    --- 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 --
    
    ```java
      /**
         * <p>Gets the canonical class name for a {@code Class}.</p>
         *
         * @param cls the class for which to get the canonical class name; may be null
         * @return the canonical name of the class, or the empty String
         * @since 3.7
         * @see Class#getCanonicalName()
         */
        public static String getCanonicalName(final Class<?> cls) {
            return getCanonicalName(cls, StringUtils.EMPTY);
        }
    ```
    
    This is in latest commons-lang.
    
    getCanonicalName returns null or the name.  In either  the function or the class function. 


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180760561
  
    --- 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 --
    
    The risk of regression with commons-lang is surely much less than with other components is it not? But, if you are thinking that this would mean updating for the whole project.. then I can understand the scope issues.


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180577592
  
    --- 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 --
    
    For posterity, this is the stack trace that motivated this:
    ```
    org.apache.metron.stellar.dsl.functions.MathFunctions and org.apache.metron.stellar.dsl.functions.MathFunctions$Sqrt disagree on InnerClasses attribute
    at java.lang.Class.getDeclaringClass0(Native Method)
    at java.lang.Class.getDeclaringClass(Class.java:1235)
    at java.lang.Class.getEnclosingClass(Class.java:1277)
    at java.lang.Class.getCanonicalName(Class.java:1392)
    at org.apache.metron.stellar.dsl.functions.resolver.ClasspathFunctionResolver.resolvables(ClasspathFunctionResolver.java:250)
    ```
    The problem is in the `getCanonicalName`.  I suppose I can do a `getName`, but I'm a bit wary of even that, frankly.


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180751165
  
    --- 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 --
    
    Actually, it doesn't look like `getCanonicalName()` is public in `ClassUtils`


---

[GitHub] metron pull request #985: METRON-1515: Errors loading stellar functions curr...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/985#discussion_r180770770
  
    --- 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 --
    
    Yeah, the problem here is that anything that touches stellar is going to percolate to every part of the project.  That's the risk that I'm trying to avoid.


---