Closed
Description
SQLe Version
main
Describe the bug
MyBatis scanner panic when xml refid not found.
INFO[0000] scanner started...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9b63df]
goroutine 8 [running]:
github.com/actiontech/mybatis-mapper-2-sql/ast.(*SqlNode).GetStmt(0x0, 0xc000030160, 0xc0004e0310, 0xc, 0x1859ba0, 0xc000073b00)
/universe/vendor/github.com/actiontech/mybatis-mapper-2-sql/ast/sql.go:30 +0x3f
github.com/actiontech/mybatis-mapper-2-sql/ast.(*IncludeNode).GetStmt(0xc00000e198, 0xc000030160, 0xc, 0xc, 0x0, 0x0)
/universe/vendor/github.com/actiontech/mybatis-mapper-2-sql/ast/include.go:75 +0x1b4
github.com/actiontech/mybatis-mapper-2-sql/ast.(*QueryNode).GetStmt(0xc0004dc270, 0xc000030160, 0x7f0fd6e4f5b8, 0x30, 0xc0004dc3c0, 0x20)
/universe/vendor/github.com/actiontech/mybatis-mapper-2-sql/ast/query.go:36 +0xb6
github.com/actiontech/mybatis-mapper-2-sql/ast.(*Mapper).GetStmt(0xc0001b8680, 0xc000030160, 0xfcfd80, 0xc0001b8680, 0x0, 0x0)
/universe/vendor/github.com/actiontech/mybatis-mapper-2-sql/ast/mapper.go:57 +0xe5
github.com/actiontech/mybatis-mapper-2-sql.ParseXML(0xc0004ec000, 0xab, 0xc0004ec000, 0xab, 0x0, 0x0)
/universe/vendor/github.com/actiontech/mybatis-mapper-2-sql/parser.go:21 +0x134
github.com/actiontech/sqle/sqle/cmd/scannerd/scanners/mybatis.GetSQLFromFile(0xc0004e0260, 0xd, 0x2, 0xc0004e0260, 0xd, 0x0, 0x0)
/universe/sqle/cmd/scannerd/scanners/mybatis/mybatis.go:155 +0x67
github.com/actiontech/sqle/sqle/cmd/scannerd/scanners/mybatis.GetSQLFromPath(0x7ffe75f7298c, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
/universe/sqle/cmd/scannerd/scanners/mybatis/mybatis.go:139 +0x48e
github.com/actiontech/sqle/sqle/cmd/scannerd/scanners/mybatis.(*MyBatis).Run(0xc0005133b0, 0xfd3e58, 0xc0004bba80, 0x0, 0x0)
/universe/sqle/cmd/scannerd/scanners/mybatis/mybatis.go:50 +0x3c
github.com/actiontech/sqle/sqle/cmd/scannerd/scanners/supervisor.Start.func1(0xfcfed0, 0xc0005133b0, 0xfd3e58, 0xc0004bba80, 0xc00010e4e0)
/universe/sqle/cmd/scannerd/scanners/supervisor/supervisor.go:18 +0x45
created by github.com/actiontech/sqle/sqle/cmd/scannerd/scanners/supervisor.Start
/universe/sqle/cmd/scannerd/scanners/supervisor/supervisor.go:17 +0xfe
To Reproduce
Steps to reproduce the behavior:
- 创建一个mybatis xml 文件
<mapper namespace="Test">
<sql id="someinclude">
</sql>
<select id="select" resultType="map">
select
<include refid="someinclude2" />
from t
</select>
</mapper>
- 创建一个审核计划
- 使用SQLE scanned 对步骤1中的xml文件进行审核,假设该文件在/tmp目录下
./scannerd mybatis -A 对应的token -D /tmp/ -A 对应的审核计划名称 -H SQLE地址 -P SQLE端口
- 执行报错如描述
Expected behavior
程序不应该 panic,而是给出错误提示