JetBrains/intellij-community · error · ConfigurationException
''{0}'' is invalid extracted class name
Error message
''{0}'' is invalid extracted class name What it means
ExtractClassDialog.canRun throws ConfigurationException (JavaBundle key invalid.extracted.class.name) when the 'class name' field of the Extract Class dialog is empty or fails PsiNameHelper.isIdentifier — i.e. it is not a valid Java identifier (keyword, illegal character, digit-first, or empty).
Source
Thrown at java/java-impl-refactorings/src/com/intellij/refactoring/extractclass/ExtractClassDialog.java:183
return;
}
invokeRefactoring(processor);
}
@Override
protected void canRun() throws ConfigurationException {
final Project project = sourceClass.getProject();
final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
final List<PsiMethod> methods = getMethodsToExtract();
final List<PsiField> fields = getFieldsToExtract();
final List<PsiClass> innerClasses = getClassesToExtract();
if (methods.isEmpty() && fields.isEmpty() && innerClasses.isEmpty()) {
throw new ConfigurationException(LangBundle.message("dialog.message.nothing.found.to.extract"));
}
final String className = getClassName();
if (className.isEmpty() || !nameHelper.isIdentifier(className)) {
throw new ConfigurationException(JavaBundle.message("invalid.extracted.class.name", className));
}
/*final String packageName = getPackageName();
if (packageName.length() == 0 || !nameHelper.isQualifiedName(packageName)) {
throw new ConfigurationException("\'" + packageName + "\' is invalid extracted class package name");
}*/
for (PsiClass innerClass : innerClasses) {
if (className.equals(innerClass.getName())) {
throw new ConfigurationException(
JavaBundle.message("extracted.class.should.have.unique.name", className));
}
}
}
public @NotNull String getPackageName() {
return packageTextField.getText().trim();
}
View on GitHub (pinned to be881553f2)
Solutions
- Enter a non-empty identifier: letters/digits/underscore/'$', not starting with a digit, not a Java keyword.
- Trim accidental spaces; CamelCase names like 'ExtractedData' are fine.
- Pick a unique name relative to the source class's inner classes to also pass the subsequent uniqueness check.
Example fix
# before: Class name: extracted-data # after: Class name: ExtractedData
Defensive patterns
Strategy: validation
Validate before calling
String name = getClassName();
if (name.isEmpty() || !PsiNameHelper.getInstance(project).isIdentifier(name)) {
// highlight the class-name field with 'not a valid Java identifier'
} Try / catch
try { dialog.canRun(); } catch (ConfigurationException e) { /* fix the class name and retry */ } Prevention
- Validate identifier fields with PsiNameHelper.isIdentifier on every keystroke.
- Suggest a default name derived from the source class.
When it happens
Trigger: Leaving the class-name field empty; entering '1Class', 'my-class', 'new', or 'My Class' (space) in the name field of the Extract Class dialog.
Common situations: Users typing display-style names with spaces or dashes; names colliding with Java keywords; auto-focus lost and OK pressed with the field untouched; pasted names with whitespace or trailing punctuation.
Related errors
- Nothing found to extract
- Extracted class should have unique name. Name ''{0}'' is alr
- ''{0}'' is invalid field name for delegation
- Invalid package name: {0}
- ''{0}'' is invalid parameter name
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/202bba619f2d4663.
Report an issue: GitHub.