swagger-maven-plugin icon indicating copy to clipboard operation
swagger-maven-plugin copied to clipboard

Performance issue - JaxrsReader.scanClasspathForTags() will not complete until all classes in classpath are parsed

Open tha2015 opened this issue 7 years ago • 3 comments

(Sample project is attached. Please run run.bat script to see the issue) demo.zip

My project containing a JAR file which has an incorrect Class-Path entry (which is pointing to "/"). As a result, when I building using this plugin, the plugin will never stop because JaxrsReader.scanClasspathForTags() will try to scan whole drive for classes.

Below is the stack trace when debugging the issue:

....
Reflections.scan(URL) line: 236	
Reflections.scan() line: 203	
Reflections.<init>(Configuration) line: 128	
Reflections.<init>(Object...) line: 169	
Reflections.<init>(String, Scanner...) line: 142	
JaxrsReader.scanClasspathForTags() line: 201	


In the source code, I found the call to new Reflections("") will never stop because of the bad entry in the classpath

    private Map<String, Tag> scanClasspathForTags() {
        Map<String, Tag> tags = new HashMap<String, Tag>();
        for (Class<?> aClass: new Reflections("").getTypesAnnotatedWith(SwaggerDefinition.class)) {

Can you improve the logic to avoid scanning the whole classpath? Even if there is no bad entry in classpath, this logic still has bad performance.

Thanks.

tha2015 avatar Aug 23 '18 04:08 tha2015

Hey @tha2015, @Postremus did you make any progress with this issue? I have the same problem. Tnx

gitomjk avatar Mar 11 '20 14:03 gitomjk

I just excluded the jar with bad Class-Path entry to avoid the issue. The prolem is to find which jars are causing issue

tha2015 avatar Mar 11 '20 15:03 tha2015

Thank you for the reply! @tha2015 for the future reference, I solved it by adding param: <swaggerApiReader>com.github.kongchen.swagger.docgen.reader.SwaggerReader</swaggerApiReader> Which sets reader to the SwaggerReader ( the reader that build swagger.json on runtime). It solved the issue.

gitomjk avatar Mar 11 '20 17:03 gitomjk