Issue Details (XML | Word | Printable)

Key: JANINO-63
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Arno Unkrig
Reporter: Lars
Votes: 0
Watchers: 1
Operations

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

Combination of interface declaration with method that declares a thrown exception cannot be parsed

Created: 09/Jun/06 05:01 PM   Updated: 18/Jun/06 03:26 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Janino 2.4.3


 Description  « Hide
The following code shows two testcases that only differ in the declaration of the variable p, which is in one case an interface and in the other case an object. The problem is that the interface code cannot be parsed and throws the following exception:

java.lang.RuntimeException: A compilation unit has no enclosing scope
at org.codehaus.janino.Java$CompilationUnit.getEnclosingScope(Unknown Source)
at org.codehaus.janino.UnitCompiler.checkThrownException(Unknown Source)
at org.codehaus.janino.UnitCompiler.findIMethod(Unknown Source)
at org.codehaus.janino.UnitCompiler.compileGet2(Unknown Source)
at org.codehaus.janino.UnitCompiler.access$46(Unknown Source)
at org.codehaus.janino.UnitCompiler$7.visitMethodInvocation(Unknown Source)
at org.codehaus.janino.Java$MethodInvocation.accept(Unknown Source)
at org.codehaus.janino.UnitCompiler.compileGet(Unknown Source)
at org.codehaus.janino.UnitCompiler.compileGetValue(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile2(Unknown Source)
at org.codehaus.janino.UnitCompiler.access$13(Unknown Source)
at org.codehaus.janino.UnitCompiler$2.visitReturnStatement(Unknown Source)
at org.codehaus.janino.Java$ReturnStatement.accept(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile2(Unknown Source)
at org.codehaus.janino.UnitCompiler.access$3(Unknown Source)
at org.codehaus.janino.UnitCompiler$2.visitBlock(Unknown Source)
at org.codehaus.janino.Java$Block.accept(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile2(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile2(Unknown Source)
at org.codehaus.janino.UnitCompiler$1.visitPackageMemberClassDeclaration(Unknown Source)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Unknown Source)
at org.codehaus.janino.UnitCompiler.compile(Unknown Source)
at org.codehaus.janino.UnitCompiler.compileUnit(Unknown Source)
at jadex.parser.janinoimpl.EvaluatorBaseCopy.compileAndLoad(EvaluatorBaseCopy.java:359)
at jadex.parser.janinoimpl.EvaluatorBaseCopy.compileAndLoad(EvaluatorBaseCopy.java:390)
at jadex.parser.janinoimpl.ClassBodyEvaluatorCopy.<init>(ClassBodyEvaluatorCopy.java:125)
at jadex.parser.janinoimpl.ClassBodyEvaluatorCopy.<init>(ClassBodyEvaluatorCopy.java:69)
at jadex.parser.janinoimpl.ClassBodyEvaluatorCopy.<init>(ClassBodyEvaluatorCopy.java:54)
at jadex.parser.janinoimpl.ClassBodyEvaluatorCopy.<init>(ClassBodyEvaluatorCopy.java:21)
at Tester.main(Tester.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

import jadex.parser.janinoimpl.ClassBodyEvaluatorCopy;

public class Tester
{
public static void main(String[] args)
{
try
{
String script = "public static boolean getO() {\n" + "IPred p = new Pred();\n"+ "return p.filter();}\n";
ClassBodyEvaluatorCopy c = new ClassBodyEvaluatorCopy(script);
System.out.println("Result1: "+c.evaluate());
}
catch(Throwable t)
{ t.printStackTrace(); }

try
{
String script = "public static boolean getO() {\n" + "Pred p = new Pred();\n"+ "return p.filter();}\n";
ClassBodyEvaluatorCopy c = new ClassBodyEvaluatorCopy(script);
System.out.println("Result2: "+c.evaluate());
}
catch(Throwable t)
{ t.printStackTrace(); } }
}
}

interface IPred
{
public boolean filter() throws Exception;
}

class Pred implements IPred
{
public boolean filter()

{ return false; }

}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Lars added a comment - 10/Jun/06 03:50 AM
Sorry I think this is not a bug, as the exception is not handled in the script method. I was confused because of the strange error message. Maybe is should be "unhandled exception" or sth. similar.

Arno Unkrig added a comment - 14/Jun/06 06:00 AM
Hello Mr. Lars,

the problem seems to be that IPred.filter() is declared with "throws Exception" clause, while get0() neither declares "throws Exception" nor encloses it the method invocation in a "try { ... } catch (Exception ex) ..." statement. Actually a compilation error

Exception "Exception" is neither declared in a "throws" clause nor is it caught in a TRY...CATCH statement

should be raised rather than throwing that embarassing RuntimeException.

I will look into this... I'm on vacation right now and cannot do anything from italy

Stay tuned!

CU

Arno


Lars added a comment - 16/Jun/06 06:22 AM
Hi Arno,

yes I absolutely agree with your interpretation

Have a nice holiday
Lars


Arno Unkrig added a comment - 18/Jun/06 03:11 PM
Back home... looked into it.

Fixed in 2.4.4, now it issues a nice error like

Thrown exception of type "java.lang.Exception" is neither caught by a "try...catch" block nor declared in the "throws" clause of the declaring function