Discussion:
no error when module exports non-existing package
Victor Rudometov
2015-12-02 17:41:04 UTC
Permalink
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.
Jonathan Gibbons
2015-12-02 18:08:58 UTC
Permalink
Post by Victor Rudometov
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
Jonathan Gibbons
2015-12-02 18:09:44 UTC
Permalink
Adding Victor back into the recipients.

-- Jon
Post by Jonathan Gibbons
Post by Victor Rudometov
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
Victor Rudometov
2015-12-02 22:20:47 UTC
Permalink
Post by Jonathan Gibbons
Adding Victor back into the recipients.
-- Jon
Post by Jonathan Gibbons
Post by Victor Rudometov
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
Jonathan Gibbons
2015-12-02 22:29:15 UTC
Permalink
Post by Victor Rudometov
Post by Jonathan Gibbons
Adding Victor back into the recipients.
-- Jon
Post by Jonathan Gibbons
Post by Victor Rudometov
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
exports should never include subpackages, so "exports p;" could only
ever mean "exports public types in package p" which raises the
additional question, what if package p is not empty, but has no public
types to be exported.

-- Jon
Alex Buckley
2015-12-08 02:35:48 UTC
Permalink
Post by Jonathan Gibbons
Post by Victor Rudometov
Post by Jonathan Gibbons
Post by Victor Rudometov
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
exports should never include subpackages, so "exports p;" could only
ever mean "exports public types in package p" which raises the
additional question, what if package p is not empty, but has no public
types to be exported.
-- Jon
We disallow mistyped module names in 'requires' clauses, so I think we
should disallow mistyped package names and empty packages for 'exports'.
That is, the package must be observable in the current module and must
contain at least observable compilation unit, or a compile-time error
occurs.

This means that typo avoidance is a language feature, not a javac
feature, in contrast to the lint warnings for "missing 'requires
public'" which are pure javac.

Alex

Continue reading on narkive:
Loading...