Error message when accessing non-public type

Gunnar Morling gunnar at hibernate.org
Wed Jun 22 06:55:23 UTC 2016


Hi Alex,

Good question, I should have mentioned some more details on this.

Hibernate Validator is using the service loader here to discover constraint
validator *types*, but then it itself is going to create (and configure)
instances of these types based on the annotation properties set for
specific usages of a constraint. I.e. there will be one instance of a
validator per constraint usage (the instance obtained from the service
loader will be dropped once its type has been examined).

E.g. two instances of the constraint validator type for @Min on int would
be created here:

    class Foo {
        @Min(1)
        int bar;

        @Min(2)
        int baz;
    }

One might argue that this is a bit mis-using the service loader mechanism
and we should rather detect some sort of constraint validator factory in
charge of creating actual constraint validator instances (in which case we
could take the instance returned from the service loader as is).

But then it's working good enough in its current form and is simpler on
implementors that way (who just need to provide/expose constraint
validators and nothing more). But it explains why that export is needed
under Jigsaw.

Alternatively, an API for obtaining just the types of services (not
instances) might help with this case.

--Gunnar


More information about the jigsaw-dev mailing list