Confusing error message for inner non-public service provider
gunnar at hibernate.org
Mon Feb 6 21:33:36 UTC 2017
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
error: package com.example.internal is not visible
provides com.example.SomeService with
(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
provides com.example.SomeService with com.example.internal.
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?
More information about the jigsaw-dev