Bug 24529 - compiler must accept empty source files
Summary: compiler must accept empty source files
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-08 14:19 EDT by vlad CLA
Modified: 2002-10-17 10:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vlad CLA 2002-10-08 14:19:07 EDT
According to the Java language spec a CompilationUnit is allowed to be empty:

CompilationUnit: 
	[package QualifiedIdentifier   ;  ] {ImportDeclaration} 
{TypeDeclaration}

This means the following is a valid Java class, regardless of which package it 
is in:
-- START--
// just a single comment
-- END--

However, Eclipse compiler generates "The declared package does not match the 
expected package ..." error.

This is not an issue with javac.

Dev teams in my company use empty class skeletons like the one above when 
adding them to the source code repository before checking-in workable versions 
[that is, an empty file is added first to reserve the name in the package 
namespace and then a "real" version is added later]. Eclipse is the only IDE 
that fails to work with empty files. Apparently, there are not preference 
settings to disable this behavior.
Comment 1 Philipe Mulet CLA 2002-10-09 05:27:12 EDT
Eclipse is performing an extra check, so as to ensure that the source file is 
located in the right directory structure matching its package declaration. 
javac doesn't care, at least if you compile these file by adding them onto the 
command line. If you only put these sources on its classpath, then it will 
require them to be properly laid out, so as to infer their location based on 
their qualified name.

We relax the check for completely empty units (if you remove the comment, 
you'll notice we don't complain any longer). We thought this would be enough to 
accomodate people annoyed by the extra check, and you seem to have a use case 
where this is not flexible enough.
Comment 2 Philipe Mulet CLA 2002-10-09 08:41:07 EDT
Changed the implementation to only check for package expectation if the unit 
contains any structure (package, import, type).

Comments alone are no longer sufficient to cause some reporting.

Fixed.
Comment 3 Philipe Mulet CLA 2002-10-09 08:55:30 EDT
Also see bug 22418 for original same request for strictly empty files.
Comment 4 David Audel CLA 2002-10-17 10:32:31 EDT
Verified.