JetBrains/intellij-community · error · ConfigurationException
{0} is not a valid package name
Error message
{0} is not a valid package name What it means
Thrown by BasePackageParameterFactory.validate() in the new-project wizard when the 'Base package' field contains a string that is not a valid Java qualified package name. Validation uses PsiNameHelperImpl.isQualifiedName(), which enforces Java identifier segments separated by dots. The error is a ConfigurationException shown directly in the wizard UI.
Source
Thrown at java/java-impl/src/com/intellij/openapi/module/BasePackageParameterFactory.java:80
@Override
public String getValue() {
return myField.getText();
}
@Override
public Map<String, String> getValues() {
HashMap<String, String> map = new HashMap<>(2);
map.put(getId(), getValue());
map.put("IJ_BASE_PACKAGE_DIR", getValue().replace('.', '/'));
map.put("IJ_BASE_PACKAGE_PREFIX", StringUtil.isEmpty(getValue()) ? "" : getValue() + ".");
return map;
}
@Override
public boolean validate() throws ConfigurationException {
String value = getValue();
if (!StringUtil.isEmpty(value) && !PsiNameHelperImpl.getInstance().isQualifiedName(value)) {
throw new ConfigurationException(JavaBundle.message("base.package.project.wizard.error.x.not.valid.package", value));
}
PropertiesComponent.getInstance().setValue(IJ_BASE_PACKAGE, value);
return true;
}
};
}
@Override
public String detectParameterValue(Project project) {
PsiPackage root = JavaPsiFacade.getInstance(project).findPackage("");
if (root == null) return null;
String name = getBasePackage(root, GlobalSearchScope.projectScope(project)).getQualifiedName();
return StringUtil.isEmpty(name) ? null : name;
}
private static PsiPackage getBasePackage(PsiPackage pack, GlobalSearchScope scope) {
List<PsiPackage> subPackages = ContainerUtil.filter(pack.getSubPackages(scope), PACKAGE_CONDITION);
return subPackages.size() == 1 ? getBasePackage(subPackages.get(0), scope) : pack;View on GitHub (pinned to be881553f2)
Solutions
- Correct the value in the 'Base package' field to dot-separated Java identifiers, e.g. com.example.myapp (segments must start with a letter, $ or _ and contain only letters, digits, $ or _).
- Remove leading/trailing dots, double dots, hyphens and whitespace from the field.
- If the value looks correct, check for invisible characters (non-breaking space, trailing newline) pasted from a browser or chat message.
- Leave the field empty if the template allows a default root package.
Example fix
// before (wizard field value) com.my-app. // after com.myapp
Defensive patterns
Strategy: validation
Validate before calling
PsiNameHelper helper = PsiNameHelper.getInstance(project);
String value = basePackageField.getText().trim();
if (!value.isEmpty() && !helper.isQualifiedName(value)) {
// show inline error instead of letting validate() throw
report("Not a valid Java package name: " + value);
} Try / catch
try { parameter.validate(); } catch (ConfigurationException e) { /* show e.getMessage() in wizard, keep dialog open */ } Prevention
- Validate package names with PsiNameHelper.isQualifiedName() as the user types (document listener), not only on Next.
- Sanitize pasted text: trim, collapse whitespace, reject hyphens and empty segments early.
- Provide a sensible default base package (derived from project name) so users rarely type one manually.
When it happens
Trigger: Entering values like 'com.example.mypackage.' (trailing dot), 'com.1example' (segment starting with a digit), 'my-package' (hyphen), 'com..example' (empty segment), or whitespace anywhere in the base package field of a Java project wizard, then pressing Next/Finish.
Common situations: Copy-pasting a package path from a file system directory or Maven groupId that is not a legal Java package; pasting with a trailing newline/space; templates or automation scripts that inject an empty or malformed base package; users assuming hyphens are allowed because the folder name allows them.
Related errors
- Invalid package name: {0}
- ''{0}'' is invalid parameter class package name
- ''{0}'' is invalid destination package name
- replace.constructor.builder.error.invalid.builder.package.na
- illegal flag combination ''{0}'' and ''{1}'' in ''{2}''
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/e0382ad784cba832.
Report an issue: GitHub.