Confusing error message for inner non-public service provider

Gunnar Morling gunnar at hibernate.org
Mon Feb 6 21:33:36 UTC 2017


Hi,

I have a service provider which is a public static inner class of an
outer class with default visibility.

As per the ServiceLoader docs, service providers must be public
classes, so this provider is rightfully rejected by javac when
referenced in module-info.java. But the error message is rather
confusing:

    error: package com.example.internal is not visible
        provides com.example.SomeService with
com.example.internal.Outer.ServiceImpl;
                                                   ^
    (package com.example.internal is declared in module com.example,
but module com.example does not read it)
    error: the service implementation does not have a default
constructor: ServiceImpl
        provides com.example.SomeService with com.example.internal.
Outer.ServiceImpl

ServiceImpl declares no explicit constructor, so there should be a
default constructor. But also the referral to package visibility seems
odd. In contrast, if defining the provider in a non-inner class with
default visibility, the error message is more what I'd have expected:

    error: ServiceImpl is not public in com.example.internal; cannot
be accessed from outside package
        provides com.example.SomeService with com.example.internal.ServiceImpl;

Surely it's an edge case, but could the error message for the former
case be adjusted to look more like in the latter?

Thanks,

--Gunnar


More information about the jigsaw-dev mailing list