3131import com .intellij .openapi .actionSystem .ActionManager ;
3232import com .intellij .openapi .actionSystem .impl .SimpleDataContext ;
3333import com .intellij .openapi .application .ApplicationManager ;
34+ import com .intellij .openapi .application .ReadAction ;
3435import com .intellij .openapi .compiler .CompileContext ;
3536import com .intellij .openapi .compiler .CompileStatusNotification ;
3637import com .intellij .openapi .compiler .CompilerManager ;
@@ -271,13 +272,8 @@ private void executeMake(final VirtualFileEvent event) {
271272 VirtualFile file = event .getFile ();
272273 if ("java" .equalsIgnoreCase (file .getExtension ())) {
273274 //AS TODO: In order to use the Code Snell Detector this needs to be invoked in a Read Only Thread but part of the Dispatcher Thread
274- invokeAndWait (
275- new InvokableRunner () {
276- @ Override
277- public void run () {
278- executeMakeInUIThread (event );
279- }
280- }
275+ ReadAction .run (() ->
276+ executeMakeInUIThread (event )
281277 );
282278 }
283279 }
@@ -293,12 +289,24 @@ private void executeMakeInUIThread(final VirtualFileEvent event) {
293289 CodeSmellDetector codeSmellDetector = CodeSmellDetector .getInstance (project );
294290 boolean isOk = true ;
295291 if (codeSmellDetector != null ) {
296- List <CodeSmellInfo > codeSmellInfoList = codeSmellDetector .findCodeSmells (Arrays .asList (event .getFile ()));
297- for (CodeSmellInfo codeSmellInfo : codeSmellInfoList ) {
298- if (codeSmellInfo .getSeverity () == HighlightSeverity .ERROR ) {
299- isOk = false ;
300- break ;
292+ try {
293+ List <CodeSmellInfo > codeSmellInfoList = codeSmellDetector .findCodeSmells (Arrays .asList (event .getFile ()));
294+ for (CodeSmellInfo codeSmellInfo : codeSmellInfoList ) {
295+ if (codeSmellInfo .getSeverity () == HighlightSeverity .ERROR ) {
296+ isOk = false ;
297+ break ;
298+ }
299+ }
300+ } catch (RuntimeException e ) {
301+ // Swallow the exception if this is due to the Cannot Run Under Write Action issue
302+ if (!e .getMessage ().contains ("run under write action" )) {
303+ throw e ;
301304 }
305+ else {
306+ Logger .getInstance (ContentResourceChangeListener .class ).info (
307+ "Found 'cannot run under write action -> ignored"
308+ );
309+ }
302310 }
303311 }
304312 if (isOk ) {
0 commit comments