jts-1.13中的bug分析

jts-1.13中的bug分析

在使用jts的STRtree时,由于项目需要,需要向索引中添加数据,还会删除数据,在使用STRtree的过程中,发现无法删除数据!代码如下:

STRtree stRtree = new STRtree();
stRtree.insert(envelope, geom1);
stRtree.remove(envelope, geom1);
鉴于对jts的敬畏之心,首先怀疑是自己调用出现了问题,在参考了各种网站后,如:

发现应该是参数没有问题,过程中还调整过参数,如将item传入null,也没有任何效果。

接下来只能读源码了,呜呜呜。。。。。。

STRtree的父类AbstractSTRtree中,remove的实现如下:

protected boolean remove(Object searchBounds, Object item) {
	build();
	if (this.itemBoundables.isEmpty()) {
		Assert.isTrue(this.root.getBounds() == null);
	}
	if (getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
		return remove(searchBounds, this.root, item);
	}
	return false;
}

由于导入的是jar包,没有用源码编译,所以不能调试。那么,只能怀疑这段代码中的各个对象了。

经过各种波折后,发现build()代码中有关联,代码如下:

public void build() {
	if (this.built)
		return;
	this.root = ((this.itemBoundables.isEmpty())
			? createNode(0)
			: createHigherLevels(this.itemBoundables, -1));

	this.itemBoundables = null;
	this.built = true;
}

联合remove和build代码,发现,当remove的时候,若没有build(),则会执行:

this.itemBoundables = null;
而在remove的下一行中,如下语句:

if (this.itemBoundables.isEmpty()) {
Assert.isTrue(this.root.getBounds() == null);
}
那么,就会报出空指针异常了。

接下来,下载新版本的jts(jts-1.14),看到remove代码如下:

protected boolean remove(Object searchBounds, Object item) {
	build();
	if (getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
		return remove(searchBounds, this.root, item);
	}
	return false;
}

去掉if assert后果然不再出现问题。

然后去网站上看更新日志,粗略看了下,并没有发现remove相关的故障,应该在其他bug中一起修复的吧。

总结和反思:

不能迷信权威。
show me the code
关注使用jar包的版本更新
提供稳定高效的API,或者给出足够的定位信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值