public static int getLineNumber() {
return Thread.currentThread().getStackTrace()[3].getLineNumber();
}
"The index will change based on the JVM version. I believe it changed from 1.4 to 1.5". Resource: http://bit.ly/xLDhVJ
I have changed the index to [3] instead of [2] but try either based on the version you are using until the line number of where function was called from is correct.
Hope this helps :)