1818import com .laytonsmith .core .exceptions .ConfigCompileException ;
1919import com .laytonsmith .core .exceptions .ConfigRuntimeException ;
2020import com .laytonsmith .core .natives .interfaces .Mixed ;
21+ import java .lang .reflect .InvocationTargetException ;
2122import java .util .Collections ;
2223import java .util .List ;
2324import java .util .Set ;
@@ -248,17 +249,31 @@ public interface CodeBranch {
248249 */
249250 static Mixed ExecuteFunction (Function f , Target t , Environment env , Mixed [] args ) throws ConfigRuntimeException {
250251 if (OLD_EXEC_CACHE .contains (f .getClass ())) {
251- return ReflectionUtils .invokeMethod (f .getClass (), f , "exec" ,
252- new Class []{Target .class , Environment .class , Mixed [].class },
253- new Object []{t , env , args });
252+ return invokeOldExec (f , t , env , args );
254253 }
255254 try {
256255 return f .exec (t , env , null , args );
257256 } catch (AbstractMethodError e ) {
258257 OLD_EXEC_CACHE .add (f .getClass ());
258+ return invokeOldExec (f , t , env , args );
259+ }
260+ }
261+
262+ private static Mixed invokeOldExec (Function f , Target t , Environment env , Mixed [] args )
263+ throws ConfigRuntimeException {
264+ try {
259265 return ReflectionUtils .invokeMethod (f .getClass (), f , "exec" ,
260266 new Class []{Target .class , Environment .class , Mixed [].class },
261267 new Object []{t , env , args });
268+ } catch (ReflectionUtils .ReflectionException e ) {
269+ Throwable cause = e .getCause ();
270+ if (cause instanceof InvocationTargetException ) {
271+ cause = cause .getCause ();
272+ }
273+ if (cause instanceof ConfigRuntimeException ) {
274+ throw (ConfigRuntimeException ) cause ;
275+ }
276+ throw e ;
262277 }
263278 }
264279
@@ -269,17 +284,30 @@ static Mixed ExecuteFunction(Function f, Target t, Environment env, Mixed[] args
269284
270285 static String ExecuteProfileMessage (Function f , Environment env , Mixed [] args ) {
271286 if (OLD_PROFILE_MESSAGE_CACHE .contains (f .getClass ())) {
272- return (String ) ReflectionUtils .invokeMethod (f .getClass (), f , "profileMessage" ,
273- new Class []{Mixed [].class },
274- new Object []{args });
287+ return invokeOldProfileMessage (f , args );
275288 }
276289 try {
277290 return f .profileMessage (env , args );
278291 } catch (AbstractMethodError e ) {
279292 OLD_PROFILE_MESSAGE_CACHE .add (f .getClass ());
293+ return invokeOldProfileMessage (f , args );
294+ }
295+ }
296+
297+ private static String invokeOldProfileMessage (Function f , Mixed [] args ) {
298+ try {
280299 return (String ) ReflectionUtils .invokeMethod (f .getClass (), f , "profileMessage" ,
281300 new Class []{Mixed [].class },
282301 new Object []{args });
302+ } catch (ReflectionUtils .ReflectionException e ) {
303+ Throwable cause = e .getCause ();
304+ if (cause instanceof InvocationTargetException ) {
305+ cause = cause .getCause ();
306+ }
307+ if (cause instanceof ConfigRuntimeException ) {
308+ throw (ConfigRuntimeException ) cause ;
309+ }
310+ throw e ;
283311 }
284312 }
285313}
0 commit comments