Community
Participate
Working Groups
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.
Could you please provide a test case?
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.
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.