You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/11/22 22:46:30 UTC

[GitHub] [pulsar] phreed opened a new issue #5726: Unhandled NoClassDefFoundError in SourceConfigUtils.java (and friends)

phreed opened a new issue #5726: Unhandled NoClassDefFoundError in SourceConfigUtils.java (and friends)
URL: https://github.com/apache/pulsar/issues/5726
 
 
   **Describe the bug**
   
   I am running a custom LocalRunner under the control of Gradle.
   There is a problem in SourceConfigUtils::validate()
   When the jarClassLoader is used a ClassNotFoundException is caught.
   The catch results in using the narClassLoader which would succeed. 
   But instead a  NoClassDefFoundError is produced for which there is no catch and consequently the narClassLoader is not used.
   
   **To Reproduce**
   
   It is not entirely clear to me why NoClassDefFoundError is sometimes the thrown exception.
   The issue is that it is not an unreasonable exception to expect when a classloader is
   unable to find a particular class.
   
   **Expected behavior**
   
   The nar file does not have its sub-dependancies in the top level but in the bundled-dependencies.
   I expect it to not find the PushSource when read as a jar file and then process the file as a NAR.
   The fact that the class is not found is as expected.
   
   **Operating Environment:**
   
    - run a gradle task
   
   **Additional context**
   
   I have done some noodling around and have found that the narClassLoader would have succeeded had it been used.
   https://github.com/apache/pulsar/blob/413aa74ed68557284d6f4502456b3bef2dbd9618/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SourceConfigUtils.java#L282-L299
   The following is a trivial (but repetitive) fix that has worked for  me.
   
                   try {
                       typeArg = getSourceType(sourceClassName, jarClassLoader);
                       classLoader = jarClassLoader;
                   } 
                   catch (ClassNotFoundException e) {
                       // class not found in JAR try loading as a NAR and searching for the class
                       if (narClassLoader != null) {
                           try {
                               typeArg = getSourceType(sourceClassName, narClassLoader);
                               classLoader = narClassLoader;
                           } catch (ClassNotFoundException e1) {
                               throw new IllegalArgumentException(
                                       String.format("Source class %s must be in class path", sourceClassName), e1);
                           }
                       } else {
                           throw new IllegalArgumentException(
                                   String.format("Source class %s must be in class path", sourceClassName), e);
                       }
                  } 
                  catch (NoClassDefFoundError e) {
                       // class not found in JAR try loading as a NAR and searching for the class
                       if (narClassLoader != null) {
                           try {
                               typeArg = getSourceType(sourceClassName, narClassLoader);
                               classLoader = narClassLoader;
                           } catch (ClassNotFoundException e1) {
                               throw new IllegalArgumentException(
                                       String.format("Source class %s must be in class path", sourceClassName), e1);
                           }
                       } else {
                           throw new IllegalArgumentException(
                                   String.format("Source class %s must be in class path", sourceClassName), e);
                       }
                   }
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services