AbstractMethodError when calling Exception.printStackTrace

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.

+6
source share
1 answer

As I understand it, you launched your application inside Eclipse Helios. This may be due to the modularity of Eclipse with OSGi and a dedicated class loader: the ClassLoader hierarchy used to run your application may result in an invalid binding. It mainly depends on which exception class and which jar files you included in your path to the application class - one of your own banners may conflict with the jar file used in Eclipse itself. Can you provide more information?

I assume that you started it using the java application launch configuration. Have you checked one of the checkboxes, such as "Enable system libraries" or "Enable inherited core" or any other options?

By the way, your application will finally be launched as a separate Java virtual machine, and in this context it should work fine.

If this is not the case, run the java application with the -verbose:class command line -verbose:class and check the last line in the output before the crash, you can get an idea of ​​conflicting libraries (different at runtime compared to compilation time).

+2
source

Source: https://habr.com/ru/post/893276/


All Articles