Issue Details (XML | Word | Printable)

Key: JANINO-95
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Arno Unkrig
Reporter: Tim Steenwyk
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Janino

ClassBodyEvaluator base class can be abstract and compile fine although it shouldn't compile

Created: 29/Jun/07 04:28 PM   Updated: 22/Jul/07 04:35 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
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
    }
}


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Tim Steenwyk added a comment - 29/Jun/07 04:45 PM
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.

Arno Unkrig added a comment - 03/Jul/07 02:59 PM
The problem was that JANINO did not verify that each non-abstract class implements all abstract methods. Added that functionality; now you get

org.codehaus.janino.CompileException: Line 1, Column 1: Non-abstract class "SC" must implement method "void Base.run()"

If the fix is very urgent for you, I can create a new JANINO release. Please let me know.

CU

Arno


Tim Steenwyk added a comment - 06/Jul/07 09:31 AM
No, the fix isn't that urgent. I can wait until you release the next version.

Thanks


Arno Unkrig added a comment - 22/Jul/07 04:35 PM
2.5.8 is right out the door... have fun!