SDK 2017.1 cannot modify a read-only file using JavaCodeInsightTestFixture

Hello,

I have a plugin that has been out since almost 2 years ago: https://github.com/afcastano/AutoValuePlugin

The test suit using JavaCodeInsightTestFixture works fine using SDK 2016.3, but since I upgraded to the latest SDK I am getting this error when running the tests:

 ERROR: Cannot modify a read-only file '/src/generatebuilder/basic/BasicTestFile.java'

I have switched back to 2016.3 and it works fine.

Any ideas what could be happening?

Thanks!

 

==========================================================

Stack trace is:

ERROR: Cannot modify a read-only file '/src/generatebuilder/basic/BasicTestFile.java'.
com.intellij.util.IncorrectOperationException: Cannot modify a read-only file '/src/generatebuilder/basic/BasicTestFile.java'.
at com.intellij.psi.impl.CheckUtil.checkWritable(CheckUtil.java:47)
at com.intellij.psi.impl.source.JavaStubPsiElement.add(JavaStubPsiElement.java:72)
at com.afcastano.intellij.autovalue.generator.AutoValueHandler$1.addBuilderElements(AutoValueHandler.java:144)
at com.afcastano.intellij.autovalue.generator.AutoValueHandler$1.run(AutoValueHandler.java:101)
at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:252)
at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:234)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:171)
at com.intellij.openapi.command.WriteCommandAction$$Lambda$347/825353095.run(Unknown Source)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1023)
at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:170)
at com.intellij.openapi.command.WriteCommandAction$$Lambda$345/1769575639.run(Unknown Source)
at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:210)
at com.intellij.openapi.command.WriteCommandAction$$Lambda$346/1995147834.run(Unknown Source)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:141)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:119)
at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:212)
at ...

1
2 comments

Hi Andres,

you need to check read-only status first before performing modifications, otherwise IDEA would throw exceptions on files, locked by file system or by some version control system (e.g. Perforce). In 2017.x we added a check for that inside the test framework, so people don't forget to do that and if, the test would fail and show the problem.

See com.intellij.codeInsight.intention.FileModifier#getElementToMakeWritable for details.

 

Hope this helps,

Anna

1
Avatar
Permanently deleted user

Hi Anna

It works, thanks!

For reference, I added this to my intentions:

@Override
public boolean startInWriteAction() {
return true;
}
0

Please sign in to leave a comment.