Skip to content

Commit acf8afe

Browse files
anarchuserxeruf
authored andcommitted
fix(protocol): prevent BoardConverter from choking on faulty lines
1 parent 20b7fdf commit acf8afe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

plugin/src/shared/sc/plugin2021/xstream/BoardConverter.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import com.thoughtworks.xstream.converters.MarshallingContext
55
import com.thoughtworks.xstream.converters.UnmarshallingContext
66
import com.thoughtworks.xstream.io.HierarchicalStreamReader
77
import com.thoughtworks.xstream.io.HierarchicalStreamWriter
8+
import org.slf4j.LoggerFactory
89
import sc.plugin2021.util.Constants
910
import sc.plugin2021.Board
1011
import sc.plugin2021.FieldContent
1112

1213
class BoardConverter: Converter {
14+
companion object {
15+
val logger = LoggerFactory.getLogger(BoardConverter::class.java)
16+
}
17+
1318
override fun canConvert(type: Class<*>?): Boolean {
1419
return type == Board::class.java
1520
}
@@ -36,10 +41,14 @@ class BoardConverter: Converter {
3641

3742
while (reader.hasMoreChildren()) {
3843
reader.moveDown()
39-
val x = reader.getAttribute("x").toInt()
40-
val y = reader.getAttribute("y").toInt()
41-
val content = FieldContent.valueOf(reader.getAttribute("content"))
42-
field[y][x] = content
44+
try {
45+
val x = reader.getAttribute("x").toInt()
46+
val y = reader.getAttribute("y").toInt()
47+
val content = FieldContent.valueOf(reader.getAttribute("content"))
48+
field[y][x] = content
49+
} catch (e: NullPointerException) {
50+
logger.warn("Failed to read field")
51+
}
4352
reader.moveUp()
4453
}
4554

0 commit comments

Comments
 (0)