ZipkinSpanHandler leaks the zipkin2.Span type through its factory methods. This prevents libraries that scan types, such as Spring, from avoiding a zipkin dep. The error shows up like below.
The alternative is to not share a base class that uses a type you can't load. So, this changes AsyncZipkinSpanHandler to not extend ZipkinSpanHandler. This allows a portable change, except the more extreme interpretation, and lets spring apps exclude zipkin2.Span (or rather not include it when using brave).
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zipkinSpanHandler' defined in class path resource [brave/example/TracingAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.TypeNotPresentException: Type zipkin2.Span not present
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:211) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1131) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
... 74 common frames omitted
Caused by: java.lang.TypeNotPresentException: Type zipkin2.Span not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:1.8.0_392]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:1.8.0_392]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_392]
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:1.8.0_392]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:1.8.0_392]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_392]
at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94) ~[na:1.8.0_392]
at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:283) ~[na:1.8.0_392]
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:283) ~[na:1.8.0_392]
at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387) ~[na:1.8.0_392]
at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116) ~[na:1.8.0_392]
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72) ~[na:1.8.0_392]
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56) ~[na:1.8.0_392]
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1205) ~[na:1.8.0_392]
at java.beans.Introspector.getBeanInfo(Introspector.java:426) ~[na:1.8.0_392]
at java.beans.Introspector.getBeanInfo(Introspector.java:262) ~[na:1.8.0_392]
at java.beans.Introspector.<init>(Introspector.java:407) ~[na:1.8.0_392]
at java.beans.Introspector.getBeanInfo(Introspector.java:262) ~[na:1.8.0_392]
at java.beans.Introspector.getBeanInfo(Introspector.java:204) ~[na:1.8.0_392]
at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:278) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:189) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:173) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:244) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1401) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1263) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) ~[spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
... 84 common frames omitted
Caused by: java.lang.ClassNotFoundException: zipkin2.Span
at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_392]
at java.lang.ClassLoader.loadClass(ClassLoader.java:419) ~[na:1.8.0_392]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) ~[na:1.8.0_392]
at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ~[na:1.8.0_392]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_392]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_392]
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:1.8.0_392]
... 110 common frames omitted
ZipkinSpanHandler leaks the
zipkin2.Span
type through its factory methods. This prevents libraries that scan types, such as Spring, from avoiding a zipkin dep. The error shows up like below.The alternative is to not share a base class that uses a type you can't load. So, this changes AsyncZipkinSpanHandler to not extend ZipkinSpanHandler. This allows a portable change, except the more extreme interpretation, and lets spring apps exclude zipkin2.Span (or rather not include it when using brave).