Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

META-INF is not changed when file is removed #46

Open
MrKuip opened this issue Oct 11, 2018 · 4 comments
Open

META-INF is not changed when file is removed #46

MrKuip opened this issue Oct 11, 2018 · 4 comments

Comments

@MrKuip
Copy link

MrKuip commented Oct 11, 2018

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?

@sentinelt
Copy link
Member

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.

@MrKuip
Copy link
Author

MrKuip commented Oct 12, 2018

You are right the problem manifest itself when compiling incrementally. But it would be nice if that worked also.

Here is another problem:

  • I remove the @IndexSubclasses annotation from ExtenstionIF
  • The method ClassIndex.getSubclasses(ExtensionIF.class) returns Ext1 and Ext2. This is wrong!
  • The method ServiceLoader.load(ExtensionIF.class) returns Ext1@1 and Ext2@2. This is wrong!

@MrKuip
Copy link
Author

MrKuip commented Oct 12, 2018

Is this a solution?

  • Validate all entries in the generated files just before writing the file?
  • All entries that are not validated are removed
  • If a file has no more entries than that file is removed

Mind you, You have to know ALL the files that have been created in the past

@sentinelt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants