6

调试时,我将断点设置为从另一个(自己的)类调用方法的行。我在编辑器中step into得到一个带有堆栈跟踪标题的标题。 只要我回到有断点的班级,我就可以跳过这些。 Source not foundMyClass$Proxy$_$$_WeldClientProxy.myMethod() line: not available

我在使用 Eclipse Kepler SR 1、Eclipse Juno SR 2 和 JBoss AS 7.1.1 和 7.2 时遇到了同样的问题。

4

3 回答 3

6

That's a common problem with autogenerated code. You believe that an object of yours (let's call it A) invokes a method on another object of yours (let's call it B), but the framework has actually replaced your object B with a proxy B' whose class is autogenerated.

The proxy B' has the same interface as your original object B, and eventually forwards the invocation to B.

Autogenerated code will confuse the debugger, but if you click "step into" blindly -- without seeing the source code -- you should eventually reach your own code again. Needless to say that it's not convenient.

What you can do instead is to

  1. set a breakpoint in the class of B you are interested in
  2. use "run" instead of "step into"

That should stop into the method you are interested in. You should be able to see in the stack the autogenerate methods of the proxy that have been invoked.

Note: you might have similar problem even if you don't use any framework at all. Indeed, the java compiler (javac) already generates synthetic code sometimes, notably for anonymous classes, and bridge methods.

于 2013-10-16T12:18:03.137 回答
2

Weld has created a proxy for your class (you may want to look here for an explanation). This created proxy is the MyClass$Proxy$_$$_WeldClientProxy you see while debugging. This proxy will eventually call MyClass.myMethod(), which is your code. Put another breakpoint there and hit "Run", or go to that method and "Run to line" in Eclipse.

It would be a problem if MyClass is an interface, and you do not know which implementation will actually get called; well brute force to the rescue, add a breakpoint to every imnplementation! Having selected the method of the interface and pressing Ctrl-T (default shortcut of Eclipse) will help you find all implementations of this method.

于 2013-10-16T12:18:35.010 回答
2

老问题,但我真的想提一下步骤过滤器作为一种可能的解决方案。要“解决”该问题,您可以定义一个步进过滤器,该过滤器将跨过 Weld 代理并在您实际希望它停止的位置停止。

打开您的工作区首选项,导航到“Java -> Debug -> Step Filtering”并选择“Add Filter”。将“$Proxy*”定义为要过滤的模式。

于 2015-06-25T09:25:00.453 回答