Compilation error due to overloaded method with unavailable parameter type

Gunnar Morling gunnar at hibernate.org
Tue May 31 21:51:23 UTC 2016


Thanks to all the replies.

Yes, fest-assert is an automatic module in my case. As you expected, it
works if I specify the "-addmods java.desktop" option as well as when
adding "requires java.desktop" to the module-info.java of my module.

> If the fest-assert module uses someone else's type (BufferedImage) in its
> exported API, then it should say 'requires public java.desktop'.

Agreed, only that there is no explicit module-info.java here. For proper
modules there should be no problem, but automatic modules during migration
will expose this issue.

I agree that a more comprehensive error message would be helpful. Currently
it's quite confusing as one gets an error about a type missing one is not
working with at all.

That said, couldn't the exporting module (here java.desktop) be added
implicitly as a dependency when examining a candidate method referring to
unavailable types (here BufferedImage) in an automatic module during
resolution?

--Gunnar




2016-05-31 20:46 GMT+02:00 Remi Forax <forax at univ-mlv.fr>:

> ----- Mail original -----
> > De: "Alex Buckley" <alex.buckley at oracle.com>
> > À: "Gunnar Morling" <gunnar at hibernate.org>, "jigsaw-dev" <
> jigsaw-dev at openjdk.java.net>
> > Envoyé: Mardi 31 Mai 2016 20:19:03
> > Objet: Re: Compilation error due to overloaded method with unavailable
>       parameter type
> >
> > During overload resolution, Assertions::assertThat(BufferedImage) is a
> > potentially applicable method so a compiler must test whether your
> > actual argument's type is compatible with BufferedImage. Implementing
> > that test almost certainly involves loading BufferedImage.
> > Unfortunately, BufferedImage is not visible at compile time, because
> > your module does not read any module exporting java.awt.image (unless
> > your module explicitly 'requires java.desktop' as you found).
> >
> > If the fest-assert module uses someone else's type (BufferedImage) in
> > its exported API, then it should say 'requires public java.desktop'.
> > Then, your module which 'requires fest-assert' will end up reading
> > java.desktop. (Of course, java.desktop may not be observable in the
> > first place, either because it doesn't physically exist or because
> > -limitmods has been used. Then, the fest-assert module will rightly fail
> > to resolve, and so will your module.)
> >
> > I believe fest-assert is an automatic module, and we don't want
> > automatic modules dragging in every module in the JDK by default.
> > Automatic modules only read modules already in the module graph. Alan's
> > suggestion to run with -addmods java.desktop will put java.desktop into
> > the module graph.
>
> yes,
> i've stubbled on the very same issue, loading all the system modules if
> there is one automatic module seems wrong but at the same time i think
> javac should do a better jobs to explain the issue and even propose the
> right '-addmods ...' line.
>
> >
> > Alex
>
> cheers,
> Rémi
>
> >
> > On 5/31/2016 10:27 AM, Gunnar Morling wrote:
> > > Hi,
> > >
> > > I'm trying to compile some code with Jigsaw / Build 120 which is using
> the
> > > FEST Assert library [1]. For that purpose I copied that library to my
> > > module directory and added a dependency to my module-info.java.
> > >
> > > One class of FEST Assert I'm using, Assertions, contains several
> overloaded
> > > assertThat() methods, one of them [2]
> > > expecting java.awt.image.BufferedImage as a parameter. My code does
> *not*
> > > invoke that overloaded variant though, but rather the one taking
> List<?> as
> > > a parameter.
> > >
> > > Still I'm getting the following error:
> > >
> > >     class file for java.awt.image.BufferedImage not found
> > >
> > > I can make the error go away by adding "requires java.desktop" to
> > > module-info.java. But that seems not right, given I'm not using
> > > BufferedImage in my module at all.
> > >
> > > Is this a bug in Jigsaw? Or do I actually need that requires clause in
> > > order for overload resolution to work correctly?
> > >
> > > Thanks,
> > >
> > > --Gunnar
> > >
> > > [1] https://github.com/alexruiz/fest-assert-1.x
> > > [2]
> > >
> https://github.com/alexruiz/fest-assert-1.x/blob/1.4/src/main/java/org/fest/assertions/Assertions.java#L85
> > >
> >
>


More information about the jigsaw-dev mailing list