diff --git a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java
index 60a7152a01ff..669249084a47 100644
--- a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java
+++ b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import static com.intellij.util.xmlb.Binding.LOG;
+
class PropertyAccessor implements MutableAccessor {
private final String myName;
private final Class> myType;
@@ -72,7 +74,26 @@ class PropertyAccessor implements MutableAccessor {
throw new XmlSerializationException(e);
}
catch (InvocationTargetException e) {
- throw new XmlSerializationException(e);
+ Throwable cause = e.getCause();
+ // see KotlinXmlSerializerTest.nullInMap
+ if (cause instanceof IllegalArgumentException && myGenericType instanceof Class && ((Class)myGenericType).isEnum() && cause.getMessage().contains("Parameter specified as non-null is null:")) {
+ Object[] constants = ((Class)myGenericType).getEnumConstants();
+ if (constants.length > 0) {
+ try {
+ LOG.warn("Cannot set enum value, will be set to first enum value", e);
+ myWriteMethod.invoke(host, constants[0]);
+ return;
+ }
+ catch (IllegalAccessException e1) {
+ throw new XmlSerializationException(e);
+ }
+ catch (InvocationTargetException e1) {
+ throw new XmlSerializationException(cause);
+ }
+ }
+ }
+
+ throw new XmlSerializationException(cause);
}
}
diff --git a/platform/util/testSrc/com/intellij/util/xmlb/KotlinXmlSerializerTest.kt b/platform/util/testSrc/com/intellij/util/xmlb/KotlinXmlSerializerTest.kt
new file mode 100644
index 000000000000..ef624e25c4a9
--- /dev/null
+++ b/platform/util/testSrc/com/intellij/util/xmlb/KotlinXmlSerializerTest.kt
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2000-2017 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util.xmlb
+
+import com.intellij.util.loadElement
+import com.intellij.util.xmlb.annotations.MapAnnotation
+import com.intellij.util.xmlb.annotations.Tag
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.Test
+import java.util.*
+
+class KotlinXmlSerializerTest {
+ @Test fun internalVar() {
+ @Tag("bean")
+ class Foo {
+ internal var PLACES_MAP = ""
+ }
+
+ val data = Foo()
+ data.PLACES_MAP = "new"
+ doSerializerTest("""
+
+
+ """, data)
+ }
+
+ @Test fun nullInMap() {
+ @Tag("bean")
+ class Foo {
+ @MapAnnotation(surroundWithTag = false, surroundKeyWithTag = false, surroundValueWithTag = false)
+ var PLACES_MAP: TreeMap = TreeMap()
+ }
+
+ val data = Foo()
+ data.PLACES_MAP.put("", PlaceSettings())
+ doSerializerTest("""
+
+
+ """, data)
+
+ assertThat(XmlSerializer.deserialize(loadElement("""
+