sylvain 01/09/19 05:22:41
Modified: src/org/apache/cocoon/components/language/programming
CompiledProgrammingLanguage.java
Log:
Fix for bug #2920 : instantiate the generated class as part of the compilation
process to check for runtime exceptions in class initializers.
Revision Changes Path
1.6 +20 -1
xml-cocoon2/src/org/apache/cocoon/components/language/programming/CompiledProgrammingLanguage.java
Index: CompiledProgrammingLanguage.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/programming/CompiledProgrammingLanguage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CompiledProgrammingLanguage.java 2001/08/20 13:55:11 1.5
+++ CompiledProgrammingLanguage.java 2001/09/19 12:22:41 1.6
@@ -22,7 +22,7 @@
* A compiled programming language. This class extends
<code>AbstractProgrammingLanguage</code> adding support for compilation
* and object program files
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/08/20 13:55:11 $
+ * @version CVS $Revision: 1.6 $ $Date: 2001/09/19 12:22:41 $
*/
public abstract class CompiledProgrammingLanguage extends
AbstractProgrammingLanguage implements Contextualizable {
/** The compiler */
@@ -142,6 +142,25 @@
sourceFile.delete();
}
Class program = this.loadProgram(filename, baseDirectory);
+
+ // Try to instantiate once to ensure there are no exceptions thrown in the
constructor
+ try {
+ Object testInstance = program.newInstance();
+
+ } catch(IllegalAccessException iae) {
+ getLogger().debug("No public constructor for class " +
program.getName());
+
+ } catch(Exception e) {
+ // Unload class and delete the object file, or it won't be recompiled
+ // (leave the source file to allow examination).
+ this.doUnload(program);
+ objectFile.delete();
+
+ String message = "Error while instantiating " + filename;
+ getLogger().warn(message, e);
+ throw new LanguageException(message, e);
+ }
+
if (program == null) {
throw new LanguageException("Can't load program : " +
baseDirectory.toString() + File.separator + filename);
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]