[jdom] Catch UncheckedStreamException in JDOMUtil IDEA-340095

This exception wraps the original one `XMLStreamException` thrown from `XmlScanner.isTextWhitespace`, so we need also to handle it

GitOrigin-RevId: 8b8296e01c080751c3e4c15123f34da249541bc7
This commit is contained in:
Mikhail Mazurkevich
2023-12-08 16:43:25 +04:00
committed by intellij-monorepo-bot
parent f772a88a4c
commit ebf9bb5b23
3 changed files with 18 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
<hello>
<data attr='1'>
<HiThere>° </HiThere>
</data>
</hello>

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util
import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.JDOMUtil.MergeAttribute
import com.intellij.testFramework.PlatformTestUtil
@@ -8,6 +9,7 @@ import com.intellij.testFramework.assertions.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.jdom.Element
import org.jdom.IllegalDataException
import org.jdom.JDOMException
import org.jdom.Text
import org.junit.Test
import java.awt.Dimension
@@ -331,6 +333,12 @@ internal class JDOMUtilTest {
|</hello>""".trimMargin(), JDOMUtil.write(res))
}
@Test(expected = JDOMException::class)
fun `handling of UncheckedStreamException for unsupported symbol`() {
val testRoot = File(PathManagerEx.getCommunityHomePath(), "platform/platform-tests/testData/vfs/encoding/DegreeSignWin1251.xml")
JDOMUtil.load(testRoot)
}
private fun assertElementText(actual: Element, expected: String) {
assertThat(JDOMUtil.createOutputter("").outputString(actual)).isEqualTo(expected)
}

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.util;
import com.fasterxml.aalto.UncheckedStreamException;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.util.io.URLUtil;
@@ -215,7 +216,7 @@ public final class JDOMUtil {
xmlStreamReader.close();
}
}
catch (XMLStreamException e) {
catch (XMLStreamException | UncheckedStreamException e) {
throw new JDOMException(e.getMessage(), e);
}
finally {
@@ -233,7 +234,7 @@ public final class JDOMUtil {
xmlStreamReader.close();
}
}
catch (XMLStreamException e) {
catch (XMLStreamException | UncheckedStreamException e) {
throw new JDOMException(e.getMessage(), e);
}
}
@@ -303,7 +304,7 @@ public final class JDOMUtil {
xmlStreamReader.close();
}
}
catch (XMLStreamException e) {
catch (XMLStreamException | UncheckedStreamException e) {
throw new JDOMException(e.getMessage(), e);
}
}
@@ -323,7 +324,7 @@ public final class JDOMUtil {
xmlStreamReader.close();
}
}
catch (XMLStreamException e) {
catch (XMLStreamException | UncheckedStreamException e) {
throw new JDOMException(e.getMessage(), e);
}
}