diff --git a/platform/analysis-impl/src/com/intellij/psi/FilePropertyKeyImpl.kt b/platform/analysis-impl/src/com/intellij/psi/FilePropertyKeyImpl.kt index 3bb762b1392e..965717094437 100644 --- a/platform/analysis-impl/src/com/intellij/psi/FilePropertyKeyImpl.kt +++ b/platform/analysis-impl/src/com/intellij/psi/FilePropertyKeyImpl.kt @@ -160,9 +160,7 @@ internal class FilePropertyStringKey(name: String, persistentAttribute: FileA override fun readValue(stream: AttributeInputStream): String? = stream.readEnumeratedString() @Throws(IOException::class) - override fun writeValue(stream: AttributeOutputStream, newValue: String?) { - StringUtil.nullize(newValue).let { stream.writeEnumeratedString(it) } - } + override fun writeValue(stream: AttributeOutputStream, newValue: String?) = stream.writeEnumeratedString(newValue) } internal class FilePropertyEnumKey>(name: String, diff --git a/platform/platform-tests/testSrc/com/intellij/psi/FilePropertyKeyImplTest.java b/platform/platform-tests/testSrc/com/intellij/psi/FilePropertyKeyImplTest.java index 570f769cf110..17a810206203 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/FilePropertyKeyImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/FilePropertyKeyImplTest.java @@ -18,6 +18,7 @@ import org.junit.runners.Parameterized.Parameter; import java.util.Arrays; import java.util.Collection; +import java.util.List; @RunWith(Parameterized.class) public class FilePropertyKeyImplTest extends LightPlatformTestCase { @@ -132,6 +133,26 @@ public class FilePropertyKeyImplTest extends LightPlatformTestCase { TestCase.assertNull("We still can read null", key.getPersistentValue(file)); } + @Test + public void testStringNotModifiedWhenPersisted(){ + Assume.assumeTrue(key == STRING_KEY); + VirtualFile file = createVirtualFile("Foo.java", ""); + + List values = Arrays.asList("value", "s p a c e s", "," ,"", " ", "\t", "null", null); + for (String value : values) { + STRING_KEY.setPersistentValue(file, value); + assertEquals("Should read exactly the same string (read from memory)", value, STRING_KEY.getPersistentValue(file)); + + memKey.set(file, null); // clear memory data + assertFalse("Should not update to the same string: '" + value + "'", STRING_KEY.setPersistentValue(file, value)); + assertEquals("Should read exactly the same string (read from memory)", value, STRING_KEY.getPersistentValue(file)); + + if (!FilePropertyKeyImpl.getREAD_PERSISTENT_VALUE()) continue; + memKey.set(file, null); // clear memory data + assertEquals("Should read exactly the same string (read from file)", value, STRING_KEY.getPersistentValue(file)); + } + } + @Parameterized.Parameters(name = "{0}") public static Collection samples() { return Arrays.asList(new Object[][]{