When declaring a exception to be thrown in a method,
this is not respected when the exception is thrown. As
an example, you find attached an interface definition
(IMyTestMgr) and and implementation (MyTestMgrImpl).
The implementation defines the class and then creates
an instance of it. This instance is read by the Test
class, which then calls the test() method. Because it
is defined in the methods, the exception IOException is
expected, Instead, I receive the following stacktrace:
koala.dynamicjava.interpreter.throwable.ThrownException:
Uncaught exception
at
koala.dynamicjava.interpreter.EvaluationVisitor.visit(EvaluationVisitor.java:348)
at
koala.dynamicjava.tree.ThrowStatement.acceptVisitor(ThrowStatement.java:95)
at
koala.dynamicjava.interpreter.TreeInterpreter.interpretMethod(TreeInterpreter.java:737)
at
koala.dynamicjava.interpreter.TreeInterpreter.invokeMethod(TreeInterpreter.java:535)
at test.MyTestMgrImpl.test(Unknown Source)
at test.Test.main(Test.java:17)
Caused by:
java.io.IOException
at
java.lang.reflect.Constructor.newInstance(Native Method)
at
koala.dynamicjava.interpreter.context.MethodContext.invokeConstructor(MethodContext.java:237)
at
koala.dynamicjava.interpreter.EvaluationVisitor.visit(EvaluationVisitor.java:686)
at
koala.dynamicjava.tree.SimpleAllocation.acceptVisitor(SimpleAllocation.java:99)
at
koala.dynamicjava.interpreter.EvaluationVisitor.visit(EvaluationVisitor.java:427)
at
koala.dynamicjava.tree.VariableDeclaration.acceptVisitor(VariableDeclaration.java:193)
at
koala.dynamicjava.interpreter.TreeInterpreter.interpretMethod(TreeInterpreter.java:737)
at
koala.dynamicjava.interpreter.TreeInterpreter.invokeMethod(TreeInterpreter.java:535)
at test.MyTestMgrImpl.test(Unknown Source)
at test.Test.main(Test.java:17)
It works, if the method is called from inside the file
MyTestMgrImpl.java, but not if the method is called
from the compiled java code outside from the
interpreter. it seems the interpreter, when invoking
the method, does not check for declared exceptions.
Logged In: YES
user_id=634522
I have made a fix by myself. I have changed
EvaluationVisitor.visit(ObjectMethodCall node) like follows:
Signature changed to
public Object visit(ObjectMethodCall node) throws
Throwable {
(and also the two parent classes)
and the method invokation to
// Invoke the method
try {
return m.invoke(obj, args);
}
catch (InvocationTargetException e)
{
Class[] exa=m.getExceptionTypes();
if (0!=exa.length)
{
for (int i=0;i<exa.length;i++)
{
if
(exa[i].isInstance(e.getTargetException()))
throw e.getTargetException();
}
}
if (e.getTargetException() instanceof Error)
{
throw (Error)e.getTargetException();
}
else if (e.getTargetException() instanceof
RuntimeException)
{
throw
(RuntimeException)e.getTargetException();
}
throw new
ThrownException(e.getTargetException(), node);
}
catch (Exception e)
{
throw new CatchedExceptionError(e, node);
}
This has worked for me.