assertion fail in ` LOG.assertTrue(!ApplicationManager.getApplication().isWriteAccessAllowed());`
The code that complains is `com.intellij.psi.impl.file.JavaDirectoryServiceImpl#createClassFromTemplate(com.intellij.psi.PsiDirectory, java.lang.String, java.lang.String, boolean, java.util.Map<java.lang.String,java.lang.String>)`
After changing my code from
return this.myJavaDirectoryService.createClass(dir, newName, templateName, true, creationOptions);
to
return ApplicationManager.getApplication().runWriteAction
((Computable<PsiClass>)
() -> myJavaDirectoryService.createClass(finalDir, finalNewName, templateName, true, creationOptions));
The error still exists.
My problem is that how to make
`ApplicationManager.getApplication().isWriteAccessAllowed())`
return false?
Please sign in to leave a comment.
The assertion says there should be no write action. Please look at the stack trace (or post it here), find WriteAction there and see why it's taken. Most likely there's a way to remove it, e.g. by overriding some kind of startInWriteAction method (if you're in an intention or a quick fix).
The stack trace is
Thanks for the stack trace! It's some "com.android.newclassdialog.NewClassAction", I don't know where it comes from: definitely not from IntelliJ codebase. If it's your code, please remove that runWriteAction. If it's not, please contact the vendor of that code.
Thanks for reply.
But as in my post, after encountering the error, I add the runWriteAction, and the error still exists.
So even if I remove the runWriteAction, the result will be same.
Ah I see, there's another one in ElementCreator. In IDEA 2017.x, there's a method named "startInWriteAction" there, which you can override.