如何密切监视java.util.map以进行某些插入

时间:2021-12-25 19:36:48

I have a problem debugging someone else's Java code in Eclipse and I have narrowed the problem down to a certain entry in a java.util.Map. At some stage, a certain key is put into the map, which is causing the problem. I have already checked all "put()" and "putAll()" calls to this map object, but haven't found the location at which the erroneous entry is created.

我在Eclipse中调试其他人的Java代码时遇到问题,我已将问题缩小到java.util.Map中的某个条目。在某个阶段,某个键被放入地图中,这导致了问题。我已经检查了所有对此map对象的“put()”和“putAll()”调用,但是没有找到创建错误条目的位置。

So, the question is: How can I monitor this Map object for insertions of a certain key? Basically, I would like the code execution to stop whenever key x is inserted or updated on this map. Is this possible?

所以,问题是:如何监视此Map对象以插入某个键?基本上,我希望只要在此映射上插入或更新密钥x,代码执行就会停止。这可能吗?

Cheers,

干杯,

Martin

马丁

3 个解决方案

#1


4  

In Eclipse you can create a conditional breakpoint. This breakpoint will only trigger when your specified condition takes place. This will allow you to monitor the put methods on the map.

在Eclipse中,您可以创建条件断点。此断点仅在您指定的条件发生时触发。这将允许您监视地图上的put方法。

Step 1: Select the breakpoint properties after right clicking on your breakpoint:

步骤1:右键单击断点后选择断点属性:

如何密切监视java.util.map以进行某些插入

Step 2: Select the conditional checkbox and enter your condition:

第2步:选择条件复选框并输入您的条件:

如何密切监视java.util.map以进行某些插入

Step 3: Run your app in debug mode.

第3步:在调试模式下运行您的应用程序。

#2


1  

Who does instantiate the map? If you can set it, then provide your custom implementation that throws exception if the searched value is passed. And then you will see in stacktrace, who and when insert this value.

谁实例化地图?如果您可以设置它,那么提供您的自定义实现,如果传递搜索的值,则抛出异常。然后你将在stacktrace中看到谁和何时插入这个值。

#3


0  

After speaking to one of our seniors guys, it turns out the problem was not so much the Map, bur rather an underlying XML structure that is used to populate the map. Looks like I was following a red herring. Nevertheless, thanks a lot to everyone who replied!

在与我们的一位老人交谈之后,事实证明问题不在于Map,而是用于填充地图的基础XML结构。看起来我跟着红鲱鱼。不过,非常感谢所有回复的人!

#1


4  

In Eclipse you can create a conditional breakpoint. This breakpoint will only trigger when your specified condition takes place. This will allow you to monitor the put methods on the map.

在Eclipse中,您可以创建条件断点。此断点仅在您指定的条件发生时触发。这将允许您监视地图上的put方法。

Step 1: Select the breakpoint properties after right clicking on your breakpoint:

步骤1:右键单击断点后选择断点属性:

如何密切监视java.util.map以进行某些插入

Step 2: Select the conditional checkbox and enter your condition:

第2步:选择条件复选框并输入您的条件:

如何密切监视java.util.map以进行某些插入

Step 3: Run your app in debug mode.

第3步:在调试模式下运行您的应用程序。

#2


1  

Who does instantiate the map? If you can set it, then provide your custom implementation that throws exception if the searched value is passed. And then you will see in stacktrace, who and when insert this value.

谁实例化地图?如果您可以设置它,那么提供您的自定义实现,如果传递搜索的值,则抛出异常。然后你将在stacktrace中看到谁和何时插入这个值。

#3


0  

After speaking to one of our seniors guys, it turns out the problem was not so much the Map, bur rather an underlying XML structure that is used to populate the map. Looks like I was following a red herring. Nevertheless, thanks a lot to everyone who replied!

在与我们的一位老人交谈之后,事实证明问题不在于Map,而是用于填充地图的基础XML结构。看起来我跟着红鲱鱼。不过,非常感谢所有回复的人!