Author: bodewig
Date: Mon Jul 13 10:56:32 2009
New Revision: 793540
URL: http://svn.apache.org/viewvc?rev=793540&view=rev
Log:
try to unwrap ScriptException - unfortunately it doesn't seem to work - PR 47509
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
ant/core/trunk/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java?rev=793540&r1=793539&r2=793540&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
Mon Jul 13 10:56:32 2009
@@ -105,11 +105,16 @@
return engine.invoke("eval", String.class, getScript());
} catch (BuildException be) {
//catch and rethrow build exceptions
- throw be;
+
+ // this may be a BuildException wrapping a ScriptException
+ // deeply wrapping yet another BuildException - for
+ // example because of self.fail() - see
+ // https://issues.apache.org/bugzilla/show_bug.cgi?id=47509
+ throw unwrap(be);
} catch (Exception be) {
//any other exception? Get its cause
Throwable t = be;
- Throwable te = (Throwable) ReflectUtil.invoke(be, "getCause");
+ Throwable te = be.getCause();
if (te != null) {
if (te instanceof BuildException) {
throw (BuildException) te;
@@ -140,4 +145,21 @@
}
return ret;
}
+
+ /**
+ * Traverse a Throwable's cause(s) and return the BuildException
+ * most deeply nested into it - if any.
+ */
+ private static BuildException unwrap(Throwable t) {
+ BuildException deepest =
+ t instanceof BuildException ? (BuildException) t : null;
+ Throwable current = t;
+ while (current.getCause() != null) {
+ current = current.getCause();
+ if (current instanceof BuildException) {
+ deepest = (BuildException) current;
+ }
+ }
+ return deepest;
+ }
}
Modified:
ant/core/trunk/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml?rev=793540&r1=793539&r2=793540&view=diff
==============================================================================
---
ant/core/trunk/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
(original)
+++
ant/core/trunk/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml
Mon Jul 13 10:56:32 2009
@@ -109,4 +109,17 @@
<scripttest/>
<assertPropSet name="property2" />
</target>
+
+ <target name="testExceptionNesting"
+
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47509"
+ if="prereqs-ok">
+ <scriptdef name="quickfail" language="javascript">
+ <![CDATA[
+ self.fail("I failed!");
+ ]]>
+ </scriptdef>
+ <au:expectfailure message="I failed!">
+ <quickfail/>
+ </au:expectfailure>
+ </target>
</project>