How can I see a full log of exceptions in JAVA? [duplicate] - java

This question already has answers here:
Print full call stack on printStackTrace()?
(3 answers)
Closed 6 years ago.
When I run some java program with a command java ExceptionTest , exceptions are sometimes omitted and looks like
Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
at SOMEWHER(unknown source)
... 13 more
I'd like to see 13 more exceptions in this case. Is there an option to see all exception log?

You already see them, it's only the ridiculous way Java (and Logback by defaul) prints exceptions by default. This stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
at SOMEWHER(unknown source)
... 13 more
actually means the following program flow (from bottom to top):
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
at SOMEWHER(unknown source)
Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
at SOMEWHERE(unknown source)
The ... 13 more (N common frames omitted in Logback) only means that these exceptions were already printed before. In Logback you can restructure stack track to avoid duplicates and print stack lines always in correct order, see my blog.

there aren't 13 more exceptions. There are 13 more lines to the call stack which are identical to previous call stacks, as described here: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()

Related

Exception in Application Start Method Error in my JavaFX application [duplicate]

This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 8 months ago.
I know this question has been asked before but the answers were not able to help solve the problem.
I have literally no errors yet I am unable to run my app.
"C:\Program Files\Java\jdk-18\bin\java.exe" "-
javaagent:D:\IntelliJ IDEA Educational Edition 2021.3.2\lib\idea_rt.jar=59011:D:\IntelliJ IDEA Educational Edition 2021.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-controls\18-ea+6\javafx-controls-18-ea+6.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-graphics\18-ea+6\javafx-graphics-18-ea+6.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-base\18-ea+6\javafx-base-18-ea+6.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-fxml\18-ea+6\javafx-fxml-18-ea+6.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-web\18-ea+6\javafx-web-18-ea+6.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-media\18-ea+6\javafx-media-18-ea+6.jar" -p "C:\Users\Loni Tande\Desktop\CalApp\target\classes;C:\Users\Loni Tande\.m2\repository\com\dlsc\formsfx\formsfx-core\11.3.2\formsfx-core-11.3.2.jar;C:\Users\Loni Tande\.m2\repository\org\controlsfx\controlsfx\11.1.0\controlsfx-11.1.0.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-controls\18-ea+6\javafx-controls-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-media\18-ea+6\javafx-media-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-base\18-ea+6\javafx-base-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-web\18-ea+6\javafx-web-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\org\kordamp\ikonli\ikonli-core\12.2.0\ikonli-core-12.2.0.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-fxml\18-ea+6\javafx-fxml-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\org\kordamp\bootstrapfx\bootstrapfx-core\0.4.0\bootstrapfx-core-0.4.0.jar;C:\Users\Loni Tande\.m2\repository\org\openjfx\javafx-graphics\18-ea+6\javafx-graphics-18-ea+6-win.jar;C:\Users\Loni Tande\.m2\repository\eu\hansolo\tilesfx\11.48\tilesfx-11.48.jar;C:\Users\Loni Tande\.m2\repository\org\kordamp\ikonli\ikonli-javafx\12.2.0\ikonli-javafx-12.2.0.jar;C:\Users\Loni Tande\.m2\repository\net\synedra\validatorfx\0.1.13\validatorfx-0.1.13.jar" -m com.example.calapp/com.example.calapp.HelloApplication
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c
at javafx.graphics#18-ea/javafx.scene.image.Image.validateUrl(Image.java:1135)
at javafx.graphics#18-ea/javafx.scene.image.Image.<init>(Image.java:625)
at com.example.calapp/com.example.calapp.HelloApplication.start(HelloApplication.java:16)
at javafx.graphics#18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#18-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#18-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#18-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.base/java.net.URL.<init>(URL.java:681)
at java.base/java.net.URL.<init>(URL.java:569)
at java.base/java.net.URL.<init>(URL.java:516)
at javafx.graphics#18-ea/javafx.scene.image.Image.validateUrl(Image.java:1132)
... 11 more
Exception running application com.example.calapp.HelloApplication
Process finished with exit code 1
The above is the error I get. I do not know what to do.
This is a screenshot of my main java class.
You have to load image in File object before using it
like this
File file = new File("c:\\files\\image.png");
Image image = new Image(file.toURI().toString());

ESAPI - Getting ClassNotFoundException with ESAPI 2.2.3.1

My Code was working with org.owasp.esapi 2.2.0.0 but after upgrading to 2.2.3.1 I am getting ClassNotFoundException.
My Code is something like:
Properties esapiProps = new Properties();
try {
esapiProps.load( SecurityUtil.class.getResourceAsStream("/ESAPI.properties") );
} catch (IOException | NullPointerException e) {
logger.log(Level.SEVERE, "esapi Exception: ", e);
}
ESAPI.override( new DefaultSecurityConfiguration(esapiProps));
// ----- Then canonicalize an input -----
ESAPI.encoder().canonicalize(input);
I read the release notes and added some properties and esapi-java-logging
my ESAPI.properties (in class path)
ESAPI.printProperties=true
LogLevel=INFO
ESAPI.Encoder=org.owasp.esapi.reference.DefaultEncoder
Encoder.AllowMultipleEncoding=false
Encoder.AllowMixedEncoding=false
Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
ESAPI.Logger=org.owasp.esapi.reference.JavaLogFactory
Logger.ApplicationName=My Test Application
Logger.LogEncodingRequired=false
Logger.LogApplicationName=true
Logger.LogServerIP=true
Logger.LogFileName=ESAPI_logging_file
Logger.MaxLogFileSize=10000000
Logger.UserInfo=true
Logger.ClientInfo=true
my esapi-java-logging.properties (in class path)
handlers= java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%3$-7s] %5$s %n
but I get this exception:
[ERROR ] SRVE0315E: An exception occurred: java.lang.Throwable: org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException Encoder class (org.owasp.esapi.reference.DefaultEncoder) CTOR threw exception.
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5095)
at [internal classes]
Caused by: org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException Encoder class (org.owasp.esapi.reference.DefaultEncoder) CTOR threw exception.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
at org.owasp.esapi.ESAPI.encoder(ESAPI.java:101)
.
.
.
at sun.reflect.GeneratedMethodAccessor521.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor522.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:86)
... 8 more
Caused by: org.owasp.esapi.errors.ConfigurationException: java.lang.ClassNotFoundException: org.owasp.esapi.reference.JavaLogFactory LogFactory class (org.owasp.esapi.reference.JavaLogFactory) must be in class path.
... 17 more
Caused by: java.lang.ClassNotFoundException: org.owasp.esapi.reference.JavaLogFactory
at com.ibm.ws.classloading.internal.AppClassLoader.findClassCommonLibraryClassLoaders(AppClassLoader.java:569)
at [internal classes]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.owasp.esapi.util.ObjFactory.loadClassByStringName(ObjFactory.java:158)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:81)
... 15 more
If I change my ESAPI.properties and copy what is in https://raw.githubusercontent.com/ESAPI/esapi-java-legacy/develop/configuration/esapi/ESAPI.properties, ClassNotFoundException goes away and I get NullPointerException exception:
[ERROR ] SRVE0315E: An exception occurred: java.lang.Throwable: org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException Encoder class (org.owasp.esapi.reference.DefaultEncoder) CTOR threw exception.
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5095)
at [internal classes]
Caused by: org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException Encoder class (org.owasp.esapi.reference.DefaultEncoder) CTOR threw exception.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
at org.owasp.esapi.ESAPI.encoder(ESAPI.java:101)
.
.
.
at sun.reflect.GeneratedMethodAccessor522.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor523.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:86)
... 8 more
Caused by: java.lang.ExceptionInInitializerError
... 20 more
Caused by: java.lang.NullPointerException
... 22 more
You said that you read the release notes. The reason for your problem is a detail that you missed that was documented there. Look in those release notes, in the section labeled:
*** IMPORTANT WORKAROUND for 2.2.1.0 ESAPI Logging ***
There, it states:
Lastly, if you try to use the new ESAPI 2.2.1.0 logging, you will notice that you need to change ESAPI.Logger and also possibly provide some other logging properties as well. This is because the logger packages were reorganized to improve maintainability, but we failed to mention it. To use ESAPI logging in ESAPI 2.2.1.0 (and later), you MUST set the ESAPI.Logger property to one of:
org.owasp.esapi.logging.java.JavaLogFactory - To use the new default, java.util.logging (JUL)
org.owasp.esapi.logging.log4j.Log4JLogFactory - To use the end-of-life Log4J 1.x logger
org.owasp.esapi.logging.slf4j.Slf4JLogFactory - To use the new (to release 2.2.0.0) SLF4J logger
Between that and a careful reading of your exception stack trace:
... deleted...
Caused by: org.owasp.esapi.errors.ConfigurationException: java.lang.ClassNotFoundException: org.owasp.esapi.reference.JavaLogFactory LogFactory class (org.owasp.esapi.reference.JavaLogFactory) must be in class path.
... 17 more
Caused by: java.lang.ClassNotFoundException: org.owasp.esapi.reference.JavaLogFactory
...deleted...
I think that should explain the reason. Those classes were reorganized to different packages to accommodate SLF4J logging.
There is some typo with logger factory config in ESAPI.properties. The classes are in org.owasp.esapi.logging.*.
#ESAPI.Logger=org.owasp.esapi.logging.log4j.Log4JLogFactory
#ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory
ESAPI.Logger=org.owasp.esapi.logging.java.JavaLogFactory

Java OPC-UA Stack Client java.io.IOException: Duplicate extensions not allowed

im trying to run one of the examples coming with the OPC-UA Java Stack and getting the following Exception.
Exception in thread "main" org.opcfoundation.ua.common.RuntimeServiceResultException: org.opcfoundation.ua.common.ServiceResultException: Bad_CertificateInvalid (code=0x80120000, description="2148663296, java.io.IOException: Duplicate extensions not allowed")
at org.opcfoundation.ua.transport.TransportChannelSettings.getServerCertificate(TransportChannelSettings.java:114)
at org.opcfoundation.ua.transport.tcp.io.TcpConnection.initialize(TcpConnection.java:376)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.initialize(SecureChannelTcp.java:273)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.initialize(SecureChannelTcp.java:246)
at org.opcfoundation.ua.application.Client.createSecureChannel(Client.java:640)
at org.opcfoundation.ua.application.Client.createSecureChannel(Client.java:555)
at org.opcfoundation.ua.application.Client.createSessionChannel(Client.java:370)
at org.opcfoundation.ua.application.Client.createSessionChannel(Client.java:345)
at org.opcfoundation.ua.examples.SampleClient.main(SampleClient.java:109)
Caused by: org.opcfoundation.ua.common.ServiceResultException: Bad_CertificateInvalid (code=0x80120000, description="2148663296, java.io.IOException: Duplicate extensions not allowed")
at org.opcfoundation.ua.transport.security.Cert.<init>(Cert.java:143)
at org.opcfoundation.ua.transport.TransportChannelSettings.getServerCertificate(TransportChannelSettings.java:112)
... 8 more
Caused by: java.security.cert.CertificateParsingException: java.io.IOException: Duplicate extensions not allowed
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:169)
at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1804)
at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:195)
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:102)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
at org.opcfoundation.ua.utils.CertificateUtils.decodeX509Certificate(CertificateUtils.java:193)
at org.opcfoundation.ua.transport.security.Cert.<init>(Cert.java:136)
... 9 more
Caused by: java.io.IOException: Duplicate extensions not allowed
at sun.security.x509.CertificateExtensions.parseExtension(CertificateExtensions.java:115)
at sun.security.x509.CertificateExtensions.init(CertificateExtensions.java:88)
at sun.security.x509.CertificateExtensions.<init>(CertificateExtensions.java:78)
at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:702)
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:167)
... 15 more
I tried running another client (c#) and it works.

java.lang.reflect.Proxy: Huge exception stack trace

Here is a simple Java application:
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class Main {
interface MyInterface {
void myMethod();
}
public static void main(String[] args) {
MyInterface myInterface = (MyInterface) Proxy.newProxyInstance(Main.class.getClassLoader(), new Class[] {MyInterface.class},
new InvocationHandler() {
#Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(proxy, args);
}
});
myInterface.myMethod();
}
}
I would expect to get a simple StackOverflowError here, because I am recursively calling the same method on the proxy instance.
However, the stack trace produced by the exception contains millions of lines and hundreds of MBs in size.
The first part of the stack trace starts like this:
java.lang.reflect.UndeclaredThrowableException
at $Proxy0.myMethod(Unknown Source)
at Main.main(Main.java:22)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
... 2 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy0.myMethod(Unknown Source)
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
... 8 more
and extends to:
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy0.myMethod(Unknown Source)
... 1022 more
Then follow millions of lines like:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
at $Proxy0.myMethod(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
.......
and:
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy0.myMethod(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
at $Proxy0.myMethod(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Main$1.invoke(Main.java:18)
.......
The last printed line is (after the repeating sequence above):
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "main"
I suspected that stack trace generation mechanism was calling some methods on the proxy instance (maybe toString to print it, or something else), thus repeating the recursion over and over again (because each method call on the proxy leads to infinite recursion), but the total count of proxy method executions is 1919 (measured by incrementing a counter in the InvocationHandler.invoke method).
In my real use case I fixed the infinite recursion issue of course; I am just curious if anyone knows if this is some bug or there is a reasonable explanation?
Java version:
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
EDIT
#JiriTousek and #AndrewWilliamson kindly provided an analysis of what may be the cause for this. I implemented a simulation based on their input:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
public class Test {
private static int counter = 0;
public static void main(String[] args) {
proxy();
}
private static void proxy() {
try {
methodInvoke();
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
private static void methodInvoke() throws InvocationTargetException {
try {
myMethod();
} catch (Throwable e) {
throw new InvocationTargetException(e);
}
}
private static void myMethod() {
if (counter++ == 5) {
throw new StackOverflowError();
}
proxy();
}
}
This results in the following stack trace:
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.main(Test.java:9)
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 1 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.myMethod(Test.java:32)
at Test.methodInvoke(Test.java:22)
... 2 more
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 4 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.myMethod(Test.java:32)
at Test.methodInvoke(Test.java:22)
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 7 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.myMethod(Test.java:32)
at Test.methodInvoke(Test.java:22)
... 8 more
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 10 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.myMethod(Test.java:32)
at Test.methodInvoke(Test.java:22)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 13 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at Test.proxy(Test.java:16)
at Test.myMethod(Test.java:32)
at Test.methodInvoke(Test.java:22)
... 14 more
Caused by: java.lang.reflect.InvocationTargetException
at Test.methodInvoke(Test.java:24)
at Test.proxy(Test.java:14)
... 16 more
Caused by: java.lang.StackOverflowError
at Test.myMethod(Test.java:30)
at Test.methodInvoke(Test.java:22)
... 17 more
So, there is no line numbers growth for each stack frame.
My interpretation of this stack trace is:
When the stack overflow finally happened, a StackOverflowError was thrown
This error was caught by method.invoke() and translated into an InvocationTargetException (as per it's javadoc), with the original exception as a cause
Since this exception is a checked exception, the Proxy could not let it fall through itself, so it caught it and translated it into a UndeclaredThrowableException, again with the previous as a cause
This way, for each level of recursion before stack overflow you got two other "caused by" exceptions along with their stack traces - a lot of output. As for how much output, let's guesstimate it:
about 2000 invocations as per your post
in each invocation, the stack trace seems to grow by 5 lines
2 errors and stack traces printed for each invocation
So the biggest stack trace will have some 10000 lines, average stack trace will have about 5000 lines, everything is printed twice (once for each exception type), that sums up to about 2000 * 5000 * 2 = 20 millions of lines.
The printed stack trace is not truncated when depth of identical traces is longer than 1024 (default value). That's why the last truncated trace ends with ... 1022 more while all of the subsequent ones are printed fully.
The default can be changed by setting MaxJavaStackTraceDepth JVM argument to the desired value. When I increased it for the original example with Proxy by running it with -XX:MaxJavaStackTraceDepth=8192, the entire printed stack trace dropped to about 12500 lines, ending with:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main1$1.invoke(Main1.java:16)
... 7003 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy0.myMethod(Unknown Source)
... 7007 more
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "main"

How do I get a Java WebService to actually show me exceptions from the proxy object?

I'm chasing what should be a simple NullPointerException but a webservice proxy keeps swallowing the error.
The WS is exposed through a simple client library, that client then calls the WS. Somewhere in the WS theres an NPE and I can't find it because the stack trace only shows "$Proxy.someMethod" instead of the cause of the issue.
How can I get the stack trace from the proxy object? Is there a good strategy to log or handle these exceptions?
...
Caused by: javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:187)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:254)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:224)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:117)
******** I need the trace from this line *********
at $Proxy43.myMethod(Unknown Source)
*****************
at com.mypackage.client.MyClient.aMethod(MyClient.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
... 17 more
I've done some reading and it seems like this has to do with checked vs. unchecked exceptions. So if I were throwing an IOException I'd get the stack trace, but since there is a NullPointerException bubbling up its not giving me the trace.
Wrap your service in a try/catch block and throw the exception that's defined as the fault element of the called service in your WSDL. That way the client will get a useable stacktrace.

Categories