Community
Participate
Working Groups
Why does the createPackageDeclaration on an ICompilationUnit throws an error when the package name given as a parameter is "".
What would you expect ? This is a bogus situation...
Do you get a JavaModelException? I think this is perfectly normal according to the specs.
I would expect it to return the default package.
There is no reason to create a package declaration for the default package, because the default package means that you DON'T have a package declaration. The API states that you need to provide a valid package name and "" is not a valid package name.
For me the problem comes from the getPackageDeclaration(String) method. This method returns the default package declaration when called with an empty string. getPackageDeclarations() returns an empty list in case the compilation unit is in the default package. getPackageDeclaration(String) should throw a JavaModelException in case it is called with a name which is not a valid package name.
This is not a bug. We follow the specs. "" is not a valid package name and therefore should not be used by createPackageDeclaration(...).