[PORTLETSPEC3-23] Errata: Issue in GenericPortlet Exception Handling for Annotations Created: 13/May/13  Updated: 22/Jan/16  Resolved: 19/Aug/13

Status: Closed
Project: portletspec3
Component/s: JSR 286 Portlet Specification Errata
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: msnicklous Assignee: msnicklous
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The doView Method is defined to throw two exceptions - a PortletException
and a java.io.IOException.

-------------------------
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, java.io.IOException

{ ... }

-------------------------

However, the annotation handling code in the GenericPortlet doDispatch() method
wraps all exceptions from an annotated method as a PortletException so that
effectively a potential java.io.IOException is never thrown.

-------------------------
try {
// check if mode is cached
if ( renderModeHandlingMethodsMap.containsKey(mode) )

{ renderModeHandlingMethodsMap.get(mode).invoke(this, request, response); return; }
} catch (Exception e) { throw new PortletException(e); }
-------------------------

the processAction() and processEvent() code wraps all exceptions from annotated
methods as PortletExceptions in the same manner. The corrected exception handling
code should be something like:

Corrected:
-------------------------
try {
// check if mode is cached
if ( renderModeHandlingMethodsMap.containsKey(mode) ) { renderModeHandlingMethodsMap.get(mode).invoke(this, request, response); return; }


} catch (InvocationTargetException ex) {
// root cause
final Throwable th = ex.getCause();
// fallthru
if (th instanceof PortletException)

{ throw (PortletException) th; }

else
if (th instanceof IOException)

{ throw (IOException) th; }

else
if (th instanceof RuntimeException)

{ throw (RuntimeException) th; }

else

{ // rethrow throw new PortletException(ex); }

}
-------------------------



 Comments   
Comment by msnicklous [ 19/Aug/13 ]

updated GenericPortlet.java. Code change only; no apidoc change. See: GenericPortlet.java

Test portlet: PORTLETSPEC3_23 from portletbox.

Comment by msnicklous [ 22/Jan/16 ]

done.

Generated at Sun Feb 07 22:17:39 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.