RenameInputValidatorEx no longer shows error messages
In our custom language plugin we have extended RenameInputValidatorEx which is suggested in the javadoc of RenameInputValidator to add a custom error message to the rename dialog in case of errors. With IntelliJ 2022.1 this works fine and the error text is display properly. Unfortunately, we just now started testing our plugin with IntelliJ 2022.3.x and noticed that the dialog no longer shows our custom error message. Debugging this issue leads me to believe there is a bug in the IntelliJ code.
From 221.5591.52 I can see in RefactoringDialog.java:
protected void validateButtons() {
boolean enabled = true;
try {
setErrorText(null);
canRun();
}
catch (ConfigurationException e) {
enabled = false;
setErrorText(e.getMessage());
}
getPreviewAction().setEnabled(enabled);
getRefactorAction().setEnabled(enabled);
}
Notice how the setErrorText(null) is called before canRun() and also in the catch block, but in case canRun() were to change the error text (which it does), the validateButtons code doesn't overwrite it.
In the newer Intellij 2022.3.1 sources I see for the same method the following handling:
protected void validateButtons() {
boolean enabled = true;
try {
canRun();
}
catch (ConfigurationException e) {
enabled = false;
setErrorText(e.getMessage());
}
if (enabled) setErrorText(null);
getPreviewAction().setEnabled(enabled);
getRefactorAction().setEnabled(enabled);
}
The problem is that the RenameInputValidatorEx is called within the canRun() method and the resulting error message is then configured using the setErrorText method. In the old version, this worked fine, but in the new version, if the enabled variable is true after canRun() (which it always is, since its a local variable, except if there is a ConfigurationException, but RenameInputValidatorEx isn't allowed to throw this type of exception) it will always reset the text to null if (enabled) setErrorText(null); and thus the custom error text gets overwritten.
I was able to workaround this issue by overwriting the canRun() method in my custom RenameDialog implementation to instead of setting the error message directly in the dialog throw a ConfigurationException with the error message text, but this seems hacky and wrong usage on my side:
@Override
protected void canRun() throws ConfigurationException {
super.canRun();
final Function<String, @NlsContexts.DialogMessage String> inputValidator = RenameInputValidatorRegistry.getInputErrorValidator(getPsiElement());
if (inputValidator != null) {
final String errorMessage = inputValidator.fun(getNewName());
if (errorMessage != null) {
throw new ConfigurationException(errorMessage);
}
}
}
Could you please provide me some hints how to properly migrate / use the RenameInputValidatorEx or otherwise customize the error message displayed in the rename dialog?
Also - I tried quite hard to find the source code of
com.intellij.refactoring.ui.RefactoringDialog
to pinpoint the changes to an excat ticket, but I couldn't find it anywhere on Github https://github.com/JetBrains/intellij-community Could you maybe also point me to where I could find the source code for this class?
Thank you!
Please sign in to leave a comment.
This indeed seems to be a regression in 2022.3. Could you file an issue in YouTrack? https://youtrack.jetbrains.com/newIssue?project=IDEA
Bas
https://youtrack.jetbrains.com/issue/IDEA-316250/RenameInputValidatorEx-no-longer-shows-error-messages