Inside the catch clause, I want to print an exception trace trace:
try { ... } catch (Exception exc) { exc.printStackTrace(); ... }
But in some cases, I don't get the stack trace and instead see something like this:
Exception in thread "pool-1-thread-2" java.lang.AbstractMethodError: java.lang.Exception.printStackTrace()V ...
Usually this exception occurs if the library at runtime does not have the same version at runtime, but in this case I am working with a class from the Java library. printStackTrace is implemented in Throwable, so this method cannot be abstract in Exception or any derived class. In addition, this AbstractMethodError is not always thrown, sometimes there are other exceptions in this particular catch clause (the program flow depends on the data from the file and the current time, so sometimes another event occurs, for example ArrayIndexOutOfBoundsExceptions or IllegalStateExceptions that are thrown in my own code and that I would expect instead of a weird error).
So the question is: how is this possible for this particular AbstractMethodError?
PS: I use Eclipse Helios for Linux and use JDK 1.6.0_24 as a runtime to run my application.
Edit: There was a typo (printStrackTrace), I fixed it. It was just written out of my mind and has nothing to do with my problem. This (or should be) a standalone application, not a web application, an Eclipse RCP application, just an old Java application (more or less). The problem also occurs on another computer - also with Eclipse Helios, also with Fedora Linux, but with JDK 1.6.0_21.
To my surprise, it was indeed possible to call getClass().getName() (but no other method I tried), the exception is of type java.lang.ArrayIndexOutOfBoundsException . I was just trying to use OpenJDK 1.6.0 (because it is already installed on my system) and got different results. Instead of throwing AbstractMethodError , printStackTrace , only an empty line is printed and getMessage() returns null (instead of throwing an error). Therefore, I don’t know where exactly the exception was thrown, because the try-catch-up block in the hierarchy catches the exception to simply gracefully stop part of the application. I could catch this type of exception at some points to get an idea of ​​where it came from. But this does not explain the strange behavior of the exception itself.
Edit 2: Finally, I tracked the issue. This turned out to be the exception that happened to me yesterday on the same line, but sometimes the exception behaves strangely. I call get(int) on a List (more precisely: a ArrayList that was wrapped using Collections.unmodifiableList(List) ) with an index that is -1 (i.e. the initial value, inside the loop, this index must be changed, but by what for that reason it will not). At least now I know where to look for the ArrayIndexOutOfBoundsException fix, but I still don't know why the exception itself behaves strangely.
Edit 3: I tried Throwable.class.getMethod("printStackTrace").invoke(exc); instead of exc.printStackTrace(); and got java.lang.NoSuchMethodError: java.lang.Throwable.printStackTrace()V instead of java.lang.AbstractMethodError . I also tried to compile java files from the shell using javac and jar (an exception is raised from only one library, because it would be tiring to manually compile all banks). The result is the same. If I throw IndexArrayOutOfBoundsException on this line myself, the stack trace will print just fine. Maybe I should hope that this problem is very rare and never occurs anywhere else.