void (Sdk jdk, Project project) { ProjectJdkTable jdkTable = ProjectJdkTable.getInstance(); // Remove all JDK named as jdk.getName() // There may be several of them as findJdk just searches a list while (true) { Sdk byName = jdkTable.findJdk(jdk.getName()); if (byName == null) break; jdkTable.removeJdk(byName); } WriteAction.runAndWait(()-> jdkTable.addJdk(jdk, project)); }