calling method from 1st line in stacktrace: “MyClass.java:1”

巧了我就是萌 提交于 2019-12-09 23:04:40

问题


In my project I'm using log4j to log errors and many frameworks: AOP, spring etc.

What does it mean when I have in my stacktrace that calling was in 1st line, e.g:

com.foo.bar.MyException: Error
    at com.foo.bar.MyClass.handleException(MyClass.java:92)
    at com.foo.bar.MyClass.myMethod(MyClass.java:76)
    at com.foo.bar.MyClass.myMethod(MyClass.java:1) // <- here ???
    ...

In 1st line my Class is comment and everything is compiled correctly

MyClass.java:

/* Copyright 2011 */
package com.foo.bar;

import ...

public class MyClass implements MyInterface {...

回答1:


I've seen this phenomenon during debugging as well - stepping into a method sometimes jumps to the first line of the declared class first, then the actual method. Without being able to give you a reference, I think it's something to do with dispatch of overridden methods in some situations (covariant return types being at least one). In these cases, the compiler needs to insert a synthetic bridge method which gets called before the "real" method, and my guess is that this method gets an effective line number of 1.

In any case, I don't think it's something for you to worry about - as you can see, your own myMethod implementation gets called successfully on line 76 immediately afterwards.



来源:https://stackoverflow.com/questions/5258943/calling-method-from-1st-line-in-stacktrace-myclass-java1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!