Skip to content

Commit 6c76c65

Browse files
Use more safe approach to analyze Spring xml configs #2123 (#2126)
Use more safe approach to analyze Spring xml configs.
1 parent a6b5ff7 commit 6c76c65

File tree

1 file changed

+14
-7
lines changed
  • utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/models

1 file changed

+14
-7
lines changed

utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/models/BaseTestModel.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,21 @@ open class BaseTestsModel(
127127

128128
val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
129129
return xmlFilePaths.mapNotNullTo(mutableSetOf()) { path ->
130-
val doc = builder.parse(path.toFile())
131-
132-
val hasBeanTagName = doc.documentElement.tagName == "beans"
133-
val hasAttribute = doc.documentElement.getAttribute("xmlns") == "http://www.springframework.org/schema/beans"
134-
when {
135-
hasBeanTagName && hasAttribute -> path.toString()
136-
else -> null
130+
try {
131+
val doc = builder.parse(path.toFile())
132+
133+
val hasBeanTagName = doc.documentElement.tagName == "beans"
134+
val hasAttribute = doc.documentElement.getAttribute("xmlns") == "http://www.springframework.org/schema/beans"
135+
when {
136+
hasBeanTagName && hasAttribute -> path.toString()
137+
else -> null
138+
}
139+
} catch (e: Exception) {
140+
// Sometimes xml parsing may fail, for example, when it references external DTD schemas.
141+
// See https://stackoverflow.com/questions/343383/unable-to-parse-xml-file-using-documentbuilder.
142+
null
137143
}
144+
138145
}
139146
}
140147

0 commit comments

Comments
 (0)