Unable to complete the scan for annotations for web application [/app] due to a StackOverflowError

In my case the org.bouncycastle.asn1.DEREncodableVector class, which was causing the cyclic dependency, was served by two jars in the class path.

bcprov-jdk15on-1.47.jar and bcprov-jdk16-1.45.jar

Excluded the unwanted jar(bcprov-jdk16-1.45.jar) and it worked well


You have a cyclic dependency. org.bouncycastle.asn1.ASN1EncodableVector depends on org.bouncycastle.asn1.DEREncodableVector which depends back on org.bouncycastle.asn1.ASN1EncodableVector which ... . This is an infinite cycle and so you're getting a StackOverflowException.

If you have the Maven plugin installed in Eclipse, look at the Dependency Hierarchy and look for these classes. I found someone with a similar issue here, he solved it by looking at the dependency tree and then adding an exclusion to break the cyclic dependency.


I just encountered this problem. Others already give the answer to this problem. I would say something else.

I guess that you are using maven-shade-plugin or something alike that packaging all dependencies into an Uber jar, right?

You can see from grepcode that bcprov-jdk15on:1.52 defines DEREncodableVector as

public class DEREncodableVector extends ASN1EncodableVector

While bcprov-jdk14:1.38 defines ASN1EncodableVector as

public class ASN1EncodableVector extends DEREncodableVector

And with maven-shade-plugin, it would randomly choose a class when two or more same classes exist. And when it chooses this combination, cyclic dependency happens. If it choose other combinations, your application may work fine. It matches what you described

Yet, most of the times, it doesn't work.

It's a probabilistic event.