mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FilePropertyKey should not modify strings that are going to be persisted
This is not expected by client code. For example, TemplateDataLanguagePusher pushes Language.ANY which is serialized to empty string "". `FilePropertyKey` transformed empty string into `null` and that `null` never deserializes into Language.ANY. Now FilePropertyKey does not modify passed strings and stores them "as is" GitOrigin-RevId: eb388afbabcb2fde9c0fb979d4053e5815796e7c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
25716f6cf5
commit
d8271ffe8c
@@ -160,9 +160,7 @@ internal class FilePropertyStringKey<T>(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<T : Enum<T>>(name: String,
|
||||
|
||||
@@ -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<T> extends LightPlatformTestCase {
|
||||
@@ -132,6 +133,26 @@ public class FilePropertyKeyImplTest<T> 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<String> 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[][]{
|
||||
|
||||
Reference in New Issue
Block a user