Compilation error due to overloaded method with unavailable parameter type

Remi Forax forax at univ-mlv.fr
Tue May 31 18:46:48 UTC 2016


----- 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