Ticket #247 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Problem with EL in templates

Reported by: karel Owned by: jgou
Priority: minor Milestone: 0.4
Component: modules/kauri-template Version: trunk
Keywords: Cc:

Description

My application was throwing an org.hibernate.PersistentObjectException?,
this is caught and handled by the representationbuilder. Unfortunately while processing the template (for rendering the exception as html) a second exception occurs:

Caused by: javax.el.PropertyNotFoundException: Property 'message' is not readable on type: org.hibernate.PersistentObjectException
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:213)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
	at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
	at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
	at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at org.kauriproject.template.el.ELExpression.evaluate(ELExpression.java:47)
	at org.kauriproject.template.TextStep.executeAndProceed(TextStep.java:42)
	at org.kauriproject.template.DefaultTemplateExecutor.execute(DefaultTemplateExecutor.java:36)

When I replace ${throwable.message} with $g{throwable.message} (in throwable.xml) the problem goes away.

Change History

comment:1 Changed 3 years ago by mpo

  • Milestone changed from 0.4 to 0.4.1

comment:2 Changed 3 years ago by jgou

  • Milestone changed from 0.4.1 to 0.4

comment:3 Changed 3 years ago by jgou

I had a look at this issue with surprising results.

First of all: "message" is not an instance or class variable, so this property is inferred. The javax.el.BeanELResolver relies on the information provided by the java.beans.Introspector in the form of a java.beans.PropertyDescriptor array.

Second: org.hibernate.PersistentObjectException extends org.hibernate.exception.NestableRuntimeException, which overrides the getMethod() method and even overloads it:

  • public String getMessage();
  • public String getMessage(int);

According to the javabeans spec, this is bad practice. Unfortunately, the Introspector doesn't handle this case well, providing bad or unsufficient information to the BeanELResolver (which in its turn doesn't attempt to fix this either), causing the reported error.

Some people at seam encountered the very same issue here.

When you run into this issue, the best solution is to use
${throwable.getMessage()} instead of ${throwable.message}. $g{throwable.message} is also valid, but I wouldn't drag groovy into this.

Final statement: I think we can close this issue, since it is not really a kauri defect. However we should probably change the defaulterrorpage template (actually throwable.xml) to use ${throwable.getMessage()} to avoid this (now) known problem.

comment:4 Changed 3 years ago by jgou

(In [1718]) Fix potential problem with exceptions extending org.hibernate.exception.NestableRuntimeException?, in wich case the message property is not properly inferred.
see #247 comment:3

comment:5 Changed 3 years ago by jgou

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.