ELException Error Reading ... on type - java

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.

Related

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 resolve Error org.omg.CORBA.BAD_OPERATION exception in java ?

When I invoke method on client side, for distributed reference object, I have this message error:
Exception in thread "main" org.omg.CORBA.BAD_OPERATION:
at org.omg.CORBA.portable.ObjectImpl._get_delegate(ObjectImpl.java:18)
at org.omg.CORBA.portable.ObjectImpl._is_local(ObjectImpl.java:130)
at fr.esiag.commun._ManageDemandStub.createDemand(_ManageDemandStub.java
:28)
at fr.esiag.commun.resource.MyInvocationHandler.invoke(MyInvocationHandl
er.java:29)
at com.sun.proxy.$Proxy0.createDemand(Unknown Source)
at org.TD.TransactionDriver.main(TransactionDriver.java:55)
Can someone tell me what that means ?
BAD_OPERATION expception happens when you try to call a method that dosen't exist in the servant. I think you cast (instead of narrow) the remote object wrong. Maybe it's is relative to your previous question

Play framework 1.2.4: NullPointerException in the constructor of play.exceptions.MailException

The problem is the following:
When sending a mail in webapp running on Play framework 1.2.4 exception with following stack trace can be observed in logs:
Execution exception
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.libs.Mail.buildMessage(Mail.java:79)
at play.libs.Mail.send(Mail.java:35)
at play.mvc.Mailer.send(Mailer.java:347)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
The relevant part here is following:
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
which indicates that NullPointerException was thrown from constructor of play.exceptions.MailException (in 27th line). Source code of this constructor looks like the following:
public MailException(String message, Throwable cause) {
super(message, cause);
StackTraceElement element = getInterestingStrackTraceElement(cause);
if(element != null) {
ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName());
sourceFile = applicationClass.javaFile.relativePath(); // this line is 27th and NPE is thrown from here
source = Arrays.asList(applicationClass.javaSource.split("\n"));
line = element.getLineNumber();
}
}
So either applicationClass local variable or javaFile property is null. Could someone familiar with Play framework weird internals advise what can cause this problem?
Thanks a lot in advance
EDIT after Seb Cesbron answer
We also inspected play.libs.Mail.buildMessage(Mail.java:79) where it is clearly seen that from address is null, but after fixing that, similar exception popped up:
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.mvc.Mailer.send(Mailer.java:349)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
And there, play.mvc.Mailer.send method contains nearly 200 lines of code enclosed in try-catch block, so it got really tricky to find out what was the problem :)
Line 79 in Mail.java refers to a throw MailException because there is no from address.
The NullPointerException in MailException seems to show that there is no file associated to your mail. Are you sure that the file Mails/forgotPassword.html (or txt) exists ?

Caught Exception while trying to serialize

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

Categories

Resources