Open MrKuip opened 6 years ago
This problem manifests itself only during incremental compilation. I looked at this few years ago. The annotation processor was executed only when the class is recompiled, but I had not found any way to be notified when it is removed. ClassIndex.getSubclasses has a workaround for that - it simply ignores classes that do not exist at run-time.
I will look into this issue once again to check if there are some new ways to detect that.
You are right the problem manifest itself when compiling incrementally. But it would be nice if that worked also.
Here is another problem:
Is this a solution?
Mind you, You have to know ALL the files that have been created in the past
I would need to verify this, but I believe annotation processor does not always have an access to all of the classes processed in the past.
I use @IndexSubclasses on the interface ExtensionIF. I created a file Ext1 that subclasses ExtensionIF. I created a file Ext2 that subclasses ExtensionIF.
The method ClassIndex.getSubclasses(ExtensionIF.class) returns Ext1 and Ext2. This is good! The method ServiceLoader.load(ExtensionIF.class) returns Ext1@1 and Ext2@2. This is good!
I now remove Ext2.
The method ClassIndex.getSubclasses(ExtensionIF.class) returns Ext1. This is good! The method ServiceLoader.load(ExtensionIF.class) exits with an exception: Exception in thread "main" java.util.ServiceConfigurationError: gti.extension.ExtensionIF: Provider gti.extension.Ext2 not found at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.access$300(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at Test.main(Test.java:17)
It seems that the file META-INF/services/gti.extension.ExtensionIF is not changed when I remove a file. Is this is a bug? Is it fixable?