{"record":{"id":"a158d440adb242a3","repo":"JetBrains/intellij-community","slug":"invalid-package-name-0","errorCode":null,"errorMessage":"Invalid package name: {0}","messagePattern":"Invalid package name: (.+?)","errorType":"exception","errorClass":"OperationFailedException","httpStatus":null,"severity":"error","filePath":"java/java-impl-refactorings/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java","lineNumber":134,"sourceCode":"        }\n      }\n    }\n    return directories[0];\n  }\n\n  @Override\n  protected boolean isPossibleToRenameOriginal() {\n    //disable for anonymous classes\n    return mySourceClass.getNameIdentifier() != null;\n  }\n\n  @Override\n  protected void preparePackage() throws OperationFailedException {\n    final String targetPackageName = getTargetPackageName();\n    final PsiFile containingFile = mySourceClass.getContainingFile();\n    final boolean fromDefaultPackage = containingFile instanceof PsiClassOwner && ((PsiClassOwner)containingFile).getPackageName().isEmpty();\n    if (!(fromDefaultPackage && StringUtil.isEmpty(targetPackageName)) && !PsiNameHelper.getInstance(myProject).isQualifiedName(targetPackageName)) {\n      throw new OperationFailedException(JavaRefactoringBundle.message(\"invalid.package.name\", targetPackageName));\n    }\n    final PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(targetPackageName);\n    if (aPackage != null) {\n      final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope());\n      if (directories.length >= 1) {\n        myTargetDirectory = getDirUnderSameSourceRoot(directories);\n      }\n    }\n\n    final MoveDestination moveDestination =\n      myDestinationFolderComboBox.selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), targetPackageName), false);\n    if (moveDestination == null) return;\n\n    myTargetDirectory = myTargetDirectory != null ? WriteAction\n      .compute(() -> moveDestination.getTargetDirectory(myTargetDirectory)) : null;\n\n    if (myTargetDirectory == null) {\n      throw new OperationFailedException(\"\"); // message already reported by PackageUtil","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl-refactorings/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java#L116-L152","documentation":"JavaExtractSuperBaseDialog.preparePackage throws OperationFailedException when the target package name typed into the Extract Superclass/Extract Interface (extract base) dialog is not a valid Java qualified name. PsiNameHelper.isQualifiedName must accept it; the only exemption is extracting from the default package into the default package (both empty).","triggerScenarios":"Entering a package like 'com..foo', '.com.foo', 'com.foo.' or a keyword-containing segment ('int.x') in the package field of the Extract Superclass dialog; also whitespace-only or illegal characters (dashes, slashes).","commonSituations":"Typing directory-like paths ('src/com/foo') instead of package syntax; trailing dots from autocompletion; pasting package names containing invalid characters; users new to Java package naming rules (keyword segments, digits-first segments).","solutions":["Correct the package name to dot-separated valid Java identifiers, e.g. 'com.example.foo'.","Remove leading/trailing dots and empty segments.","Do not use Java keywords or hyphes/slashes; a segment may not start with a digit.","If the source class is in the default package, leaving the target package empty is also acceptable."],"exampleFix":"# before:\nPackage: com/example/foo\n\n# after:\nPackage: com.example.foo","handlingStrategy":"validation","validationCode":"boolean fromDefault = containingFile instanceof PsiClassOwner o && o.getPackageName().isEmpty();\nif (!(fromDefault && targetPackageName.isEmpty())\n    && !PsiNameHelper.getInstance(project).isQualifiedName(targetPackageName)) {\n  // block OK with 'invalid package name' before running the dialog action\n}","typeGuard":null,"tryCatchPattern":"try { dialog.preparePackage(); } catch (OperationFailedException e) { /* invalid package name: correct the field */ }","preventionTips":["Validate the package field live with PsiNameHelper.isQualifiedName.","Use package completion rather than free text; reject trailing dots and path separators."],"tags":["java","intellij","refactoring","extract-superclass","package-name","validation","user-input"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}