From 93714ca9943816268d24853329c98be441924cbb Mon Sep 17 00:00:00 2001 From: Srikanth Adayapalam Date: Wed, 25 May 2016 19:30:55 +0530 Subject: [PATCH] 8047024: 7 ANNOT tests in JCK9 test suite fail with an AssertionError for exception_index Fix incorrect assertion about exception index already being set. Reviewed-by: mcimadamore --- .../javac/code/TypeAnnotationPosition.java | 13 ++++--- .../typeAnnotations/8047024/T8047024.java | 36 +++++++++++++++++ .../typeAnnotations/8047024/T8047024_01.java | 39 +++++++++++++++++++ 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024.java create mode 100644 langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024_01.java diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java index 835acf14b26..71d7aac0b05 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java @@ -148,9 +148,10 @@ public class TypeAnnotationPosition { // For exception parameters, index into exception table. In // com.sun.tools.javac.jvm.Gen.genCatch, we first use this to hold - // the catch type index. Then in + // the catch type's constant pool entry index. Then in // com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions we // use that value to determine the exception table index. + // When read from class file, this holds private int exception_index = Integer.MIN_VALUE; // If this type annotation is within a lambda expression, @@ -303,13 +304,13 @@ public class TypeAnnotationPosition { } public int getExceptionIndex() { - Assert.check(exception_index >= 0, "exception_index does not contain a bytecode offset"); + Assert.check(exception_index >= 0, "exception_index is not set"); return exception_index; } public void setExceptionIndex(final int exception_index) { - Assert.check(hasCatchType(), "exception_index already contains a bytecode offset"); - Assert.check(exception_index >= 0, "Expected a valid bytecode offset"); + Assert.check(!hasExceptionIndex(), "exception_index already set"); + Assert.check(exception_index >= 0, "Expected a valid index into exception table"); this.exception_index = exception_index; } @@ -330,8 +331,8 @@ public class TypeAnnotationPosition { } public void setCatchInfo(final int catchType, final int startPos) { - Assert.check(this.exception_index < 0, - "exception_index already contains a bytecode index"); + Assert.check(!hasExceptionIndex(), + "exception_index is already set"); Assert.check(catchType >= 0, "Expected a valid catch type"); this.exception_index = -((catchType | startPos << 8) + 1); } diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024.java b/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024.java new file mode 100644 index 00000000000..e749bc73b15 --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8047024 + * @summary AssertionError: exception_index already contains a bytecode offset + * @compile T8047024_01.java + * @compile -XDsave-parameter-names=true T8047024.java + */ + +public class T8047024 { + public static void main(String [] args) { + T8047024_01.run(); + } +} diff --git a/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024_01.java b/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024_01.java new file mode 100644 index 00000000000..fa1a06f748f --- /dev/null +++ b/langtools/test/tools/javac/annotations/typeAnnotations/8047024/T8047024_01.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +public class T8047024_01 { + + @Target(ElementType.TYPE_USE) + @interface TA {} + + public static void run() { + try { + System.out.println(""); + } catch (@TA Throwable e) { + + } + } +}