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

Sub interfaces are added to the service list #59

Open
ST-DDT opened this issue Mar 25, 2020 · 0 comments
Open

Sub interfaces are added to the service list #59

ST-DDT opened this issue Mar 25, 2020 · 0 comments

Comments

@ST-DDT
Copy link

ST-DDT commented Mar 25, 2020

I have a sub-interface that extends my @IndexSubclasses interface, that class gets added to the META-INF/services file. This causes an exception in the application at runtime.

Classindex: v3.9

java.util.ServiceConfigurationError: com.example.Interface: Provider com.example.SubInterface could not be instantiated
	at java.util.ServiceLoader.fail(ServiceLoader.java:232)
	at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at com.example.Registry.init(Registry.java:78)
	... plenty more
Caused by: java.lang.InstantiationException: com.example.SubInterface
	at java.lang.Class.newInstance(Class.java:427)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
	... 73 more
Caused by: java.lang.NoSuchMethodException: com.example.SubInterface.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 74 more

Test-Sourcen

@IndexSubclasses
public interface IndexedInterface {
}
public interface SubInterface extends IndexedInterface {
}
class IndexTest {

    @Test
    void testGetAll() {
        ServiceLoader.load(IndexedInterface.class)
                .forEach(System.out::println); // <-- Boom
    }

}
@ST-DDT ST-DDT changed the title Sub interface classes are added to the service list Sub interfaces are added to the service list Mar 25, 2020
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

1 participant