From f6edd6d285138e7220f081e4bb26a8bb420b3f1b Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Thu, 30 Nov 2006 17:23:10 +0300 Subject: [PATCH] Fix reported stack for exceptions in object constructor. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch contains: The fix of “this” reporting issue in the JET. Test which checks that stack depth is right. --- vm/jitrino/src/jet/structs.h | 2 - vm/tests/smoke/exception/ExceptionStackTest.java | 58 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletions(-) diff --git a/vm/jitrino/src/jet/structs.h b/vm/jitrino/src/jet/structs.h index 0640347..9d53b76 100644 --- a/vm/jitrino/src/jet/structs.h +++ b/vm/jitrino/src/jet/structs.h @@ -567,7 +567,7 @@ struct MethInfo /** Tests whether the method is constructor. */ bool meth_is_ctor(void) { - return strcmp(meth_name(), ""); + return !strcmp(meth_name(), ""); } /** Tests whether the method is constructor of Exception. */ bool meth_is_exc_ctor(void) diff --git a/vm/tests/smoke/exception/ExceptionStackTest.java b/vm/tests/smoke/exception/ExceptionStackTest.java new file mode 100644 index 0000000..6851a65 --- /dev/null +++ b/vm/tests/smoke/exception/ExceptionStackTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Pavel Afremov + * @version $Revision: 1.0 $ + */ +package exception; + +/** + * Testt checks that reported stack deth is right + */ +class ExceptionStackTest { + // Large enought but not too for test performace reasona + private static final int MAX_DEPTH = 100; + + // Constructor calls itself and throw runtime exception on max depth + ExceptionStackTest(int c) { + if (c > 0) { + new ExceptionStackTest(c - 1); + } else { + throw new RuntimeException("Test"); + } + } + + // run test and check that it throws exception with right stack depth + public static void main(String[] args) { + try { + new ExceptionStackTest(MAX_DEPTH); + System.out.println("FAIL"); + } catch (RuntimeException rte) { + StackTraceElement[] stack = rte.getStackTrace(); + int stackLength = stack.length; + + if (stackLength < MAX_DEPTH) { + System.out.println("FAIL : Stack length should be more " + + MAX_DEPTH + ", but it's " + stackLength); + } else { + System.out.println("PASS : Stack length is " + stackLength); + } + } catch (Throwable th) { + System.out.println("FAIL"); + } + } +} -- 1.4.1