sylvain     01/09/19 05:22:16

  Modified:    src/org/apache/cocoon/components/language/programming Tag:
                        cocoon_20_branch 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
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.5 +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.1.1.1.2.4
  retrieving revision 1.1.1.1.2.5
  diff -u -r1.1.1.1.2.4 -r1.1.1.1.2.5
  --- CompiledProgrammingLanguage.java  2001/08/20 14:07:27     1.1.1.1.2.4
  +++ CompiledProgrammingLanguage.java  2001/09/19 12:22:16     1.1.1.1.2.5
  @@ -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.1.1.1.2.4 $ $Date: 2001/08/20 14:07:27 $
  + * @version CVS $Revision: 1.1.1.1.2.5 $ $Date: 2001/09/19 12:22:16 $
    */
   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]

Reply via email to