Buggy code:
public class OptimizeImportsAction extends AnAction { @ NonNls private static final String HELP_ID = "editing.manageImports" ; public void actionPerformed ( AnActionEvent event ) { } public static void actionPerformedImpl ( final DataContext dataContext ) { final Project project = PROJECT . getData ( dataContext ) ; if ( project == null ) { return ; } PsiDocumentManager . getInstance ( project ) . commitAllDocuments ( ) ; final Editor editor = BaseCodeInsightAction . getInjectedEditor ( project , EDITOR . getData ( dataContext ) ) ; final VirtualFile [ ] files = VIRTUAL_FILE_ARRAY . getData ( dataContext ) ; PsiFile file = null ; PsiDirectory dir ; if ( editor != null ) { file = PsiDocumentManager . getInstance ( project ) . getPsiFile ( editor . getDocument ( ) ) ; if ( file == null ) return ; dir = file . getContainingDirectory ( ) ; } else if ( ( files != null ) && ( ReformatCodeAction . areFiles ( files ) ) ) { final ReadonlyStatusHandler . OperationStatus operationStatus = ReadonlyStatusHandler . getInstance ( project ) . ensureFilesWritable ( files ) ; if ( ! ( operationStatus . hasReadonlyFiles ( ) ) ) { new OptimizeImportsProcessor ( project , ReformatCodeAction . convertToPsiFiles ( files , project ) , null ) . run ( ) ; } return ; } else { Project projectContext = PROJECT_CONTEXT . getData ( dataContext ) ; Module moduleContext = MODULE_CONTEXT . getData ( dataContext ) ; if ( ( projectContext != null ) || ( moduleContext != null ) ) { final String text ; if ( moduleContext != null ) { text = CodeInsightBundle . message ( "process.scope.module" , moduleContext . getName ( ) ) ; } else { text = CodeInsightBundle . message ( "process.scope.project" , projectContext . getPresentableUrl ( ) ) ; } LayoutProjectCodeDialog dialog = new LayoutProjectCodeDialog ( project , null , CodeInsightBundle . message ( "process.optimize.imports" ) , text , false ) ; dialog . show ( ) ; if ( ! ( dialog . isOK ( ) ) ) return ; if ( moduleContext != null ) { new OptimizeImportsProcessor ( project , moduleContext ) . run ( ) ; } else { new OptimizeImportsProcessor ( projectContext ) . run ( ) ; } return ; } PsiElement element = PSI_ELEMENT . getData ( dataContext ) ; if ( element == null ) return ; if ( element instanceof PsiDirectoryContainer ) { dir = ( ( PsiDirectoryContainer ) ( element ) ) . getDirectories ( ) [ 0 ] ; } else if ( element instanceof PsiDirectory ) { dir = ( ( PsiDirectory ) ( element ) ) ; } else { file = element . getContainingFile ( ) ; if ( file == null ) return ; dir = file . getContainingDirectory ( ) ; } } boolean processDirectory ; boolean includeSubdirectories ; if ( ApplicationManager . getApplication ( ) . isUnitTestMode ( ) ) { includeSubdirectories = processDirectory = false ; } else <START_BUG> if ( ! ( EditorSettingsExternalizable . getInstance ( ) . getOptions ( ) . SHOW_OPIMIZE_IMPORTS_DIALOG ) ) { <END_BUG> includeSubdirectories = processDirectory = false ; } else { final LayoutCodeDialog dialog = new LayoutCodeDialog ( project , CodeInsightBundle . message ( "process.optimize.imports" ) , file , dir , null , OptimizeImportsAction . HELP_ID ) ; dialog . show ( ) ; if ( ! ( dialog . isOK ( ) ) ) return ; EditorSettingsExternalizable . getInstance ( ) . getOptions ( ) . SHOW_OPIMIZE_IMPORTS_DIALOG = ! ( dialog . isDoNotAskMe ( ) ) ; ReformatCodeAction . updateShowDialogSetting ( dialog , "\"Optimize<seq2seq4repair_space>Imports\"<seq2seq4repair_space>dialog<seq2seq4repair_space>disabled" ) ; processDirectory = dialog . isProcessDirectory ( ) ; includeSubdirectories = dialog . isIncludeSubdirectories ( ) ; } if ( processDirectory ) { new OptimizeImportsProcessor ( project , dir , includeSubdirectories ) . run ( ) ; } else { new OptimizeImportsProcessor ( project , file ) . run ( ) ; } } public void update ( AnActionEvent event ) { } private static boolean isOptimizeImportsAvailable ( final PsiFile file ) { } }

Fix:
if ( ( ! ( EditorSettingsExternalizable . getInstance ( ) . getOptions ( ) . SHOW_OPIMIZE_IMPORTS_DIALOG ) ) && ( file != null ) ) {