Bug 119440 - [compiler] generates error on missing package statement and assumes package based on source directory path
Summary: [compiler] generates error on missing package statement and assumes package b...
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-06 11:41 EST by Meyer Franklin CLA
Modified: 2006-11-27 09:25 EST (History)
0 users

See Also:


Attachments
test case to reproduce the bug as described (3.60 KB, application/x-zip-compressed)
2005-12-06 13:32 EST, Meyer Franklin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Meyer Franklin CLA 2005-12-06 11:41:15 EST
I am receiving an error: "The declared package does not match the expected package..." in a java file that has NO package statement.  All of the java code for a specific package lives in an appropriately named directory structure, e.g. com/mycorp/util.  Let's say one .java file in this directory does NOT have any package statement.  I get the error on that file: "The declared package does not match the expected package com.mycorp.util" on Line 1 where a package statement would normally be.  The file compiles fine, and assumes the package statement for the directory structure that it lives in and puts the resulting .class file in the target com/mycorp/util output folder. 

Using Sun's javac for the same project, there is NO error generated from the compiler AND the .class file is located at the same level as the target "com" folder.  The result from Sun's comiler is what I expect to happen in with Eclipse.  A warning instead of an error would be appropriate, but the location of the .class file should never be assumed.
Comment 1 Olivier Thomann CLA 2005-12-06 11:44:13 EST
Could you please provide a test case?
Comment 2 Meyer Franklin CLA 2005-12-06 13:32:05 EST
Created attachment 31217 [details]
test case to reproduce the bug as described

Please find attachment bug119440.zip.  This contains a test project which demonstrates the bug as described.
Comment 3 Maxime Daniel CLA 2006-11-27 09:25:33 EST
On Eclipse 3.2 M3, the message reads 'The declared package "" does not match the expected package "com.mycorp.util"', which, in my opinion, clearly states what Eclipse complains about. Regarding how Eclipse decides which package a compilation units belongs to, I would contend that JLS 3 7.2.1 leaves plenty of room to tools, and that Eclipse's choice is acceptable. In other words, the spec explicitly states that tools will have to make choices within a space that have few documented constraints. Both Eclipse and javac have made choices. These choices happen to be different, to have each merits of its own, and to be both compatible with the spec. This bug could then possibly trigger an enhancement request, but this is not a problem per se.