Our application exposes some methods via JMX, which we invoke using JVisualVM.
This works well normally, but sometimes a method call will abort with an exception inside the application. In that case, instead of showing the error message from the exception, JVisualVM shows an error message
java.rmi.UnmarshalException [...] error unmarshaling return;
nested exception is: java.lang.ClassNotFoundException [...]
This is rather unhelpful and confusing; we would like JVisualVM to show the real error message.
What we have found so far:
It seems that JMX will serialize and deserialize any exception thrown during a call. In our case however, the exceptions are custom exceptions which are not part of the JDK. Thus when invoking the methods via JVisualVM, JVisualVM cannot show the exception because deserialization fails due to the unknown custom exception class.
Right now, as a workaround we wrap all methods exposed via JMX in a try-catch
block which just does
throw new RuntimeException("Error invoking method:"+e);
This works, because it converts any exception to a string, but seems rather unelegant and verbose.
- Is there some generic way to tell JMX to not serialize exceptions? Something like "always convert exceptions to strings"?
- We use Spring's MBeanExporter. Is there maybe a mechanism in Spring to handle this?
Edit
We know that we could configure JVisualVM to load the classes in question. However, we would like JVisualVM to work without a special config. Also, it may run an a system where the application code is not even available.