jaxrs-analyzer icon indicating copy to clipboard operation
jaxrs-analyzer copied to clipboard

Loading static values from system classloader

Open koebbingd opened this issue 7 years ago • 2 comments

The backtrace states that an analyzed class can not be found. This error is generated by InstructionBuilder.getStaticValue:

   field = Class.forName(containingClass.replace('/', '.')).getDeclaredField(name);

When I replace this line of code with

   final String className = containingClass.replace('/', '.');
   final Class<?> clazz = ContextClassReader.getClassLoader().loadClass(className);
   field = clazz.getDeclaredField(name);

I get rid of the error, but I wonder if the intended functionality is still given.

koebbingd avatar Oct 25 '17 07:10 koebbingd

Yes, the problem is that this can't be changed atm, since the Maven plugin has two different classloaders (with their set of class instances). So yes, it has quite a few side effects... This needs some further refactoring on the overall class loading first.

sdaschner avatar Nov 18 '17 13:11 sdaschner

Hey @sdaschner - we met at JCrete. We bumped into your project and try using it to generate Swagger files out of existing JAX-RS Resource classes. We ran this issue here. I started looking at the source code to understand, couldn't figure out something and I will be glad for any pointers to save me time:

  1. You mentioned Maven plugin has different class-loaders. I thought that all the Maven plugin needs to provide are two strings: (1) project class paths (i.e. resource classes packages), (2) class paths (i.e. list of jars). Once you have that, you can easily instantiate a JaxRs Analyzer and run. If that is so, why the reliance on Maven class loaders?

  2. I saw in the code that ContextClassLoader is static. Any reason why static, and instantiate it when you create the Project Analyzer?

asafm avatar Jan 14 '18 14:01 asafm