no error when module exports non-existing package

Victor Rudometov victor.rudometov at oracle.com
Wed Dec 2 22:20:47 UTC 2015


On 02.12.2015 21:09, Jonathan Gibbons wrote:
> Adding Victor back into the recipients.
>
> -- Jon
>
> On 12/02/2015 10:08 AM, Jonathan Gibbons wrote:
>>
>>
>> On 12/02/2015 09:41 AM, Victor Rudometov wrote:
>>> Hi,
>>> Javac does not complain if user exports a package that does not 
>>> exist. If it was not done intentionally, it would be good to report 
>>> an error, or at least a warning.
>>> Today was the third time I saw the code with a typo or just 
>>> incorrect package name in module-info's exports statement.
>>>
>>> Thanks.
>>> Victor.
>>>
>>
>> I agree we should improve javac in this area. We probably need some 
>> spec clarification from Alex on the intent here. See JLS 8, 7.4.3 
>> Observability of a package.  In particular, that says that a package 
>> is observable if a subpackage is observable.  javac tries to honor 
>> that specification, but there are well known hard-to-fix bugs in this 
>> area.
>>
>> As for module declarations,   if  p.q.Class exists in a module and no 
>> other classes anywhere in p or its subpackages, is it OK to export p 
>> from the module?  From the point of view of the module, the package 
>> is observable, but it seems intuitively wrong to allow an export of a 
>> package that contains no types. In other words, if we are going to 
>> catch typos in exported package names, I think we ought to consider 
>> "empty" packages as well as mistyped packages.
>>
>> -- Jon
>

I agree with you, it is worth to consider disallowing "empty" packages 
together with mistyped ones.
While I do not see the use for mistyped non-existing packages there are 
cases when "empty" might be useful. F.e., is the case of p.q.Class and 
p.r.OtherClass it would be easier to export just p, rather than both p.q 
and p.r. However I'd prefer to write explicit p.q and p.r.

Victor




More information about the jigsaw-dev mailing list