Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Running the command:
ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new StringReader(scriptText)), scriptName, scriptBaseClass, new Class[0], null)
does not throw an exception when scriptBaseClass is an abstract class. From what I can tell it just creates a derived abstract class. Trying to call the abstract method causes a java.lang.AbstractMethodError.
If this behavior is by design it would be nice to have an option to compile a non-abstract class (as this is what I need, I want it to fail in this case).
Example:
Base.java
public abstract class Base{ public abstract run(); }
CompileTheClass.java
public class CompileTheClass{ String scriptText = "public void m(){ System.out.println(\"Got here\"); }"; public void compileAndRun(){ Base obj = (Base)ClassBodyEvaluator.createFastClassBodyEvaluator( new Scanner(null, new StringReader(scriptText)), "MyScript", "Base", new Class[0], null); obj.run(); // Crash here } }
I take back what I said, it doesn't create a derived abstract class. Using reflection, the compiled object (obj in the example) does not appear to be abstract even though it doesn't contain the run() method. Also creating an instance of the class wouldn't be possible if it was abstract.