@@ -212,27 +212,38 @@ public ActionReturn handleCustomActionExecution(ActionsExecutable actionProvider
212212 } catch (IllegalAccessException e ) {
213213 throw new RuntimeException ("Fatal error trying to execute custom action method: " + customAction , e );
214214 } catch (InvocationTargetException e ) {
215- if (e .getCause () != null ) {
216- if (e .getCause ().getClass ().isAssignableFrom (IllegalArgumentException .class )) {
217- throw new IllegalArgumentException (e .getCause ().getMessage () + " (rethrown)" , e .getCause ());
218- } else if (e .getCause ().getClass ().isAssignableFrom (EntityNotFoundException .class )) {
219- throw new EntityNotFoundException (e .getCause ().getMessage () + " (rethrown)" , ref +"" , e .getCause ());
220- } else if (e .getCause ().getClass ().isAssignableFrom (FormatUnsupportedException .class )) {
221- String format = ((FormatUnsupportedException )e .getCause ()).format ;
222- throw new FormatUnsupportedException (e .getCause ().getMessage () + " (rethrown)" , e .getCause (), ref +"" , format );
223- } else if (e .getCause ().getClass ().isAssignableFrom (UnsupportedOperationException .class )) {
224- throw new UnsupportedOperationException (e .getCause ().getMessage () + " (rethrown)" , e .getCause ());
225- } else if (e .getCause ().getClass ().isAssignableFrom (EntityException .class )) {
226- int code = ((EntityException )e .getCause ()).responseCode ;
227- throw new EntityException (e .getCause ().getMessage () + " (rethrown)" , ref +"" , code );
228- } else if (e .getCause ().getClass ().isAssignableFrom (IllegalStateException .class )) {
229- throw new IllegalStateException (e .getCause ().getMessage () + " (rethrown)" , e .getCause ());
230- } else if (e .getCause ().getClass ().isAssignableFrom (SecurityException .class )) {
231- throw new SecurityException (e .getCause ().getMessage () + " (rethrown)" , e .getCause ());
215+ Throwable cause = e .getCause (); // Get the real cause once
216+
217+ if (cause != null ) {
218+ if (cause instanceof IllegalArgumentException ) {
219+ throw new IllegalArgumentException (cause .getMessage () + " (rethrown)" , cause );
220+ } else if (cause instanceof EntityNotFoundException ) {
221+ throw new EntityNotFoundException (cause .getMessage () + " (rethrown)" , ref + "" , cause );
222+ } else if (cause instanceof FormatUnsupportedException ) {
223+ FormatUnsupportedException fue = (FormatUnsupportedException ) cause ;
224+ throw new FormatUnsupportedException (cause .getMessage () + " (rethrown)" , cause , ref + "" , fue .format );
225+ } else if (cause instanceof UnsupportedOperationException ) {
226+ throw new UnsupportedOperationException (cause .getMessage () + " (rethrown)" , cause );
227+ } else if (cause instanceof EntityException ) {
228+ EntityException ee = (EntityException ) cause ;
229+ throw new EntityException (cause .getMessage () + " (rethrown)" , ref + "" , ee .responseCode , cause );
230+ } else if (cause instanceof IllegalStateException ) {
231+ throw new IllegalStateException (cause .getMessage () + " (rethrown)" , cause );
232+ } else if (cause instanceof SecurityException ) {
233+ throw new SecurityException (cause .getMessage () + " (rethrown)" , cause );
234+ } else {
235+ // Log the UNHANDLED cause WITH its stack trace
236+ log .error ("Unhandled target exception type [{}], rethrowing as a RuntimeException. Original cause:" ,
237+ cause .getClass ().getName (), cause );
238+ // Rethrowing a generic wrapper, preserving the actual cause
239+ throw new RuntimeException ("Unhandled exception during custom action execution: " + customAction , cause );
232240 }
233- log .error ("Target exception class not identified, rethrowing as a RuntimeException: {}" , e .getCause ().toString ());
241+ } else {
242+ // InvocationTargetException happened, but getCause() is null. Less common.
243+ // Wrap the InvocationTargetException itself.
244+ log .error ("InvocationTargetException occurred with no cause during custom action execution: {}" , customAction , e );
245+ throw new RuntimeException ("Fatal error trying to execute custom action method (no specific cause): " + customAction , e );
234246 }
235- throw new RuntimeException ("Fatal error trying to execute custom action method: " + customAction , e );
236247 }
237248 }
238249 if (result != null ) {
0 commit comments