Skip to content

Sub interfaces are added to the service list #59

@ST-DDT

Description

@ST-DDT

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
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions