Caught Exception while trying to serialize - java

I've the following error in my logs
[6/6/11 17:16:33:558 CEST] 00000005 WASSession E MTMBuffWrapper storeObject SESN0200E: Caught Exception while trying to serialize.
[6/6/11 17:16:33:558 CEST] 00000005 WASSession E MTMHashMap handlePropertyHits SESN0202E: Failed to replicate attribute changeBankStatusForm
I've identified the object which raise this error, this object is huge, a lot of attribute containing them self attributes
How can I identify the exact attribute which raise the serialization error
Thanks

Update it appears that your application server is handling the exception wrongly, so you'd have to manually look through all fields and check if their types implement Serializable
You are most likely handling your exception wrong. I assume you are doing:
try { ..
} catch(Exception ex) {
System.out.println("Caught Exception while trying to serialize"); // wrong
ex.printStackTrace(); // better
logger.error("Serialization problem", ex); //best
}
If that's the case - you can't get any more info, because you've swallowed the exception. You should call ex.printStackTrace() instead (or use a logging framework)
Then the exception will tell you which class fails the serialization, and so you will be able to mark it as Serializable

Related

How to catch any exception from activiti bpmn subprocess?

I have some serviceTask in my sequential sub process. Any of this tasks can generate exception.
And i need to catch this, do some logic and go back to iterative process.
I have tried bpmn:boundaryEvent like this :
but it generates
Caused by: org.activiti.engine.ActivitiException: Errors while parsing:
[Validation set: 'activiti-executable-process' | Problem: 'activiti-seq-flow-invalid-target'] : Invalid target for sequenceflow, the target isn't defined in the same scope as the source - [Extra info : processDefinitionId = notificationsNewsSendProc | id = sid-db0a2e21-f460-4e32-84f4-f2ca88481434 | ] ( line: 100, column: 223)
id = sid-db0a2e21-f460-4e32-84f4-f2ca88481434 is sequenceFlow from error event to external task.
i read here https://www.activiti.org/userguide/#exceptionMapping that i can route exception from service task, but it is not my way, because i dont want to stop subprocess. I just need to catch exception and go back.
Please help me with xml diagram of catching exceptions.

Slf4j with Log4j does not print wrapped exception (caused by) when wrapper exception has a message

First example:
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws Exception {
try {
throw new RuntimeException(new NullPointerException("NPE"));
} catch (RuntimeException e) {
logger.error("Error:", e);
}
}
}
Output:
Error:
java.lang.RuntimeException: java.lang.NullPointerException: NPE
at Main.main(Main.java:10)
In the second example we just add a message to the RuntimeException also:
throw new RuntimeException("RTE", new NullPointerException("NPE"));
Output:
Error:
java.lang.RuntimeException: RTE
at Main.main(Main.java:10)
Why is NullPointerException not logged in this case?
Note: e.printStackTrace() prints both exceptions in both cases:
java.lang.RuntimeException: RTE
at Main.main(Main.java:10)
Caused by: java.lang.NullPointerException: NPE
... 1 more
Versions:
slf4j-api: 1.7.12
slf4j-log4j12: 1.7.12
log4j: 1.2.17
Giving it a possible try using all the docs and debugging I could, I hope this helps in whatever way it can :
#param message the message object to log.
#param t the exception to log, including its stack trace.
public void error(Object message, Throwable t)
So both your cases are including the stack-trace of the RuntimeException thrown by the statement of code. Not much of a difference.
Case 1 : throw new RuntimeException(new NullPointerException("NPE"));
Quoting from the RuntimeException Java-Doc and NullPointerException Java-Doc
public RuntimeException(Throwable cause)
Constructs a new runtime exception with the specified cause and a
detail message of (cause==null ? null : cause.toString()) (which
typically contains the class and detail message of cause). This
constructor is useful for runtime exceptions that are little more than
wrappers for other throwables.
public NullPointerException(String s)
Constructs a NullPointerException with the specified detail message.
So that possibly answers the first part of your question where java.lang.RuntimeException is thrown during execution which is caused by the new NullPointerException but as cause==null evaluates to false the cause.toString() is printed i.e java.lang.NullPointerException and now since this exception itself has a message passed that follows as NPE
Note : You have mentioned the cause as NullPointerException in your code.(hence cause==null evaluates to false)
Case 2 : throw new RuntimeException("RTE", new NullPointerException("NPE"))
public RuntimeException(String message, Throwable cause)
Constructs a new runtime exception with the specified detail message
and cause. Note that the detail message associated with cause is not
automatically incorporated in this runtime exception's detail message.
In which case you end up getting java.lang.RuntimeException being thrown with a message RTE since your cause is a child of RuntimeException itself and the parent is caught first, it gets executed and the child is not reached in this case.
I noticed that in the log4j.properties file I'm using there is the following line:
log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
It seems to be causing the caused by elements to be omitted when the exception is logged.
Once removed, the full stack trace is logged.
There are 2 issues.
Why is NullPointerException not logged in this case[throw new RuntimeException("RTE", new NullPointerException("NPE"));]?
Ans:
Actually SLF4J has no impact on that case. It is pure JVM issue. In JVM, it is required to compute every passed parameter before function call. If you follow this 2 examples, you can easily understood that issue.
Example 1:
public class Main {
public static void main(String[] args) {
throw new RuntimeException(new NullPointerException("NPE"));
}
}
Output:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException: NPE // Here, "java.lang.NullPointerException: NPE" - this portion is used as message according to RuntimeException
at Main.main(Main.java:3)
Caused by: java.lang.NullPointerException: NPE
... 1 more
Here, "java.lang.NullPointerException: NPE" - this portion is used as message according to RuntimeException which one is also generated from another exception NullPointerException(String s)
Example 2:
public class Main {
public static void main(String[] args) {
throw new RuntimeException("RTE", new NullPointerException("NPE"));
}
}
Output:
Exception in thread "main" java.lang.RuntimeException: RTE // Here "RTE" is used as message
at Main.main(Main.java:3)
Caused by: java.lang.NullPointerException: NPE
... 1 more
Here "RTE" is used as message.
In your code, you have used 3 times exceptions. That's not good coding.
Why e.printStackTrace() prints both exceptions in both cases?
e.printStackTrace() prints this throwable and its backtrace to the standard error stream. It prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err
As your output is:
java.lang.RuntimeException: RTE
at Main.main(Main.java:10)
Caused by: java.lang.NullPointerException: NPE
... 1 more
The first line of output["java.lang.RuntimeException: RTE"]
contains the result of the toString() method for this Throwable
object.
Remaining lines represent data previously recorded by the method fillInStackTrace()
The backtrace for a throwable with an initialized, non-null cause
should generally include the backtrace for the cause. The format of
this information depends on the implementation. For your clear
understanding, go through the backtrace example below:
HighLevelException: MidLevelException: LowLevelException
at Junk.a(Junk.java:13)
at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
at Junk.c(Junk.java:23)
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
... 1 more
Caused by: LowLevelException
at Junk.e(Junk.java:30)
at Junk.d(Junk.java:27)
at Junk.c(Junk.java:21)
... 3 more
"... 1"
These lines indicate that the remainder of the stack trace for this
exception matches the indicated number of frames from the bottom of
the stack trace of the exception that was caused by this exception
(the "enclosing" exception).
Resource Link:
What printstacktrace does?
SLF4J-Log4J does not appear to have disabled logging
For SLF4J, you can go through
sysout-over-slf4j module redirects all calls to System.out and
System.err to an SLF4J defined logger with the name of the fully
qualified class in which the System.out.println (or similar) call
was made, at configurable levels.
idalia SLF4J Extensions allows logging at a level determined at
runtime rather than compile-time.
I had similar problem when I was using Slf4j Logger in my Apache Spark application running on cluster mode. As I found out problem in my case was caused by JVM optimization related to OmitStackTraceInFastThrow which was basically not printing whole stack just top level error without any details.
In your case this might be hiding error message from NullPointerException. Try adding this argument to JVM -XX:-OmitStackTraceInFastThrow when starting your application and let us know if it works.

Java Casting Error Using CFPOP

My CF9 application running on a windows server pops mail. When I attempt to retrieve the entire body of the message, I sometimes get the following error...
Error:
An exception occurred while retrieving mail.
The cause of this exception was: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart.
Location:
Line 335 in controllers\Submissions.cfc
Not sure if this is pertinent, but FYI every message will have an image attached and the whole process usually works fine. This problem is intermittent.
My Questions
Any idea what causes this?
Any idea how to catch and resolve this issue?
I suspect I'll need to drop down into java, but not sure where to start.
Code Fragments
<cfscript>
// setup variables array for all cfpop calls
CFPopAttributes = {
server = request.pop.server,
port = request.pop.port,
username = request.pop.username,
password = request.pop.password,
timeout = 300
};
</cfscript>
<cfpop
action="getall"
name="entireEmail"
uid="#uid#"
attachmentpath="#originalsPath#"
attributecollection="#CFPopAttributes#" // Line 335
generateuniquefilenames="true"
/>
NOTE: I added the comment "Line 335" above to communicate exactly where in the code the template is breaking. If I move the attributecollection up or down (before/after other attributes), the error always breaks at the attributecollection line.
Stack Trace
struct [Filtered - 1 of 8 keys hidden]
Detail: An exception occurred while invoking an event handler method from Application.cfc. The method name is: onRequest.
Message: Event handler exception.
RootCause:
[struct]
Detail: The cause of this exception was: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart.
Message: An exception occurred while retrieving mail.
RootCause:
[struct]
Message: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart
StackTrace: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart
at coldfusion.mail.EmailTable.getAttachmentName(EmailTable.java:819)
at coldfusion.mail.EmailTable.populate(EmailTable.java:283)
at coldfusion.mail.PopImpl.getMails(PopImpl.java:241)
at coldfusion.tagext.net.PopTag$1.run(PopTag.java:433)
at java.security.AccessController.doPrivileged(Native Method)
at coldfusion.tagext.net.PopTag.doStartTag(PopTag.java:429)
at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2799)
at cfSubmissions2ecfc1952269377$funcGETEMAIL.runFunction(D:\home\wwwroot\controllers\Submissions.cfc:335)

How to catch "Unable to sendViaPost to url"?

I am running two axis2 services which communicate with each other. On every service startup I get this error:
2014-02-24 13:02:31,258 [INFO ] HTTPSender - Unable to sendViaPost to url[http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:446)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Since this error is not important, I would like to catch it and to print some better error message instead of the whole stack trace. Where do I catch this error?
Looking at the stack trace, I don't think you can catch it. Catching it would require that you own code somewhere in the Thread where the exception is being thrown.
Looking at the lowest stack in the trace shows this:
at java.lang.Thread.run(Thread.java:724)
To me this says that the exception is occurring in a thread most likely started by Axis. Because of this you can't catch it and show an error message.
If this is expected behavior, the best you can do is to configure your logging framework not to show INFOs from Axis. Be aware that this may mean you'll also miss more useful error messages as well.
All in all, I would focus on how to solve the "Unable to sendViaPost" from happening rather than suppressing the logging statement.
To answer your comment question: As you can see from the stack trace, the exception is not caught by any client code but is bubbled up to Thread itself. This is the stopping point for an Exception and where it stops. If you were going to catch it you'd have to have code in its call stack (which you don't, since when the thread is created by Axis a new call stack is created for the new thread Axis starts).
Read more here. The only difference in your case is that since the exception is not thrown on the main thread the program doesn't exit, but the thread where the exception occurs is terminated.
To sum it up: You have no code in the call stack and therefore cannot catch the exception. The only other option is to turn of INFO statements for Axis.
If I am understanding the question properly you're attempting to catch something that is not the exception that is being thrown.
This:
HTTPSender - Unable to sendViaPost to url[http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]
is what is being attempted. When it failed it's throwing a ConnectException.
Which you can simply catch with
try{
//Code that Makes the Connection
}
catch (ConnectException e)
{
e.printStackTrace();//Or What ever your message may be
}
Without seeing some code it's impossible to give a definitive answer. But this likely will solve the problem.
One Caveat, if you do catch a ConnectException to suppress it, you could suppress when there actually is a problem that would also throw a ConnectException.
If this is happening when you are starting up the server you might want to check why this is happening before trying to suppress it.
If it's refusing the connection that you are attempting you might want to ensure where it is connecting to has an available socket to connect to.
2014-02-24 13:02:31,258 [INFO] HTTPSender - Unable to
sendViaPost to
url[http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]
Well, if you look closely, the message which you are trying to catch isn't an ERROR at all. It's an INFO log generated from HTTPSender. Only thing which you should catch in this entire stacktrace is java.net.ConnectException and check for message Connection refused.
You can make it easier for your clients though and provide a message, by wrapping the java.net.ConnectException with message Connection refused or throwing a custom exception with the original exception as the cause.
UPDATE
java.net.ConnectException is an elementary exception in network transactions. Generally standard libraries do not catch them unless there is something specific to be done.
In this case, if you are unable to catch hold of java.net.ConnectException, then you can look out to catch AxisFault thrown by org.apache.axis2.description.OutInAxisOperationClient.send.
Below snippet may be useful for you.
try {
...
} catch (RemoteException ex) {
if(ex instanceof AxisFault){
logger.error("Axis Fault error: " + ((AxisFault)ex).getFaultString());
throw new CustomExcpetion(" Custom Message ");
}
}
Also note that AxisFault is a subclass of java.rmi.RemoteException and this will not get caught when you use java.lang.Exception in a catch statement.
Shishir

ELException Error Reading ... on type

I'm getting an exception when displaying my jsp page that tries to invoke a function defined getCurrentlocation() in type Person.
The function is invoked by ${person.currentlocation} in the jsp file.
type Exception report
message javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
I am pretty new to jsp technology. Maybe someone could help me out!
Thanks,
Benjamin
This particular ELException is a wrapper exception. This is usually only thrown when invoking the getter method itself has thrown an exception. Something like the following is happening under the covers when this ELException is been thrown:
Object bean;
String property;
Method getter;
// ...
try {
getter.invoke(bean);
} catch (Exception e) {
String message = String.format("Error reading '%s' on type %s", property, bean.getClass().getName());
throw new ELException(message, e);
}
You should look further down in the stacktrace for the real root cause. The complete stacktrace is usually just available in server logs. The real root cause is the bottommost exception of the stacktrace. E.g. the below one is caused by a NullPointerException being thrown in the getter method.
javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
at ...
at ...
at ...
Caused by: java.lang.NullPointerException
at **.person.Person.getCurrentlocation(Person.java:42)
at ...
at ...
The information about the real root cause (the exception type and the line number) should give you enough clues to nail down the problem.
Again, this is not a problem with EL in general. It's just your own code which caused the problem.

Categories

Resources