On 11/19/18 9:27 PM, Jayaprakash Artanareeswaran wrote:
I have the following folder structure in a module

my.module
          -module-info.java
          - p
              -- C.java
              -- q
                  --- D.java

where C.java contains only the package declaration and D.java is empty.

When I run javac with --module-source-path and all the individual files as arguments the 
compiler is happy and reports no error. This behavior is different from Eclipse compiler 
which reports an error about "declaring a named package because this compilation 
unit is associated to the named module". Is this because empty compilation units are 
considered to be part of unnamed modules or because the D.java and hence package q are 
omitted?

I have been trying to find out the relevant part of the spec or any 
documentation that defines this behavior, but couldn't find anything on this. 
Can someone please tell me what the right behavior is and point me to the 
relevant documentation?

This Eclipse bug has more details - 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=540067

Regards,
Jay


As long as C.java contains a package declaration for "package p;", I would expect that to be OK. There is (or should be) no presumption about what other declarations may appear in that file.

If D.java is empty, there is nothing to complain about!

Generally, javac cares about the contents of files, as defined by the syntax rules in JLS.   The conventions about filenames only kick in when applied to a type element declared in that file.

-- Jon

Reply via email to