Initial load
diff --git a/test/java/lang/Class/Cast.java b/test/java/lang/Class/Cast.java
new file mode 100644
index 0000000..0f57c22
--- /dev/null
+++ b/test/java/lang/Class/Cast.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4881275
+ * @summary (reflect) Class.cast() - typesafe cast desired
+ *
+ * @compile -source 1.5 Cast.java
+ * @run main Cast
+ */
+
+public class Cast {
+ static class Foo {}
+
+ public static void main(String argv[]) throws Exception {
+ Object o = Foo.class.newInstance();
+ Foo f = Foo.class.cast(o);
+ if (f == null) throw new Error();
+ Foo f2 = Foo.class.cast(null);
+ }
+}
diff --git a/test/java/lang/Class/EnumPoseur.class b/test/java/lang/Class/EnumPoseur.class
new file mode 100644
index 0000000..3a8575d
--- /dev/null
+++ b/test/java/lang/Class/EnumPoseur.class
Binary files differ
diff --git a/test/java/lang/Class/EnumPoseur.java.src b/test/java/lang/Class/EnumPoseur.java.src
new file mode 100644
index 0000000..5d30fdb
--- /dev/null
+++ b/test/java/lang/Class/EnumPoseur.java.src
@@ -0,0 +1,11 @@
+/*
+ *
+ *
+ * This file is used indirectly by the IsEnum.java test. The class
+ * file generated from this source file has class file version 48;
+ * i.e. it is not a version 49 class file generated by target 1.5.
+ */
+class EnumPoseur extends java.lang.Enum {
+ private EnumPoseur(){
+ }
+}
diff --git a/test/java/lang/Class/IsAnnotationType.java b/test/java/lang/Class/IsAnnotationType.java
new file mode 100644
index 0000000..0019cf3
--- /dev/null
+++ b/test/java/lang/Class/IsAnnotationType.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4891872 4988155
+ * @summary Check isAnnotation() method
+ * @author Joseph D. Darcy
+ */
+
+import java.lang.annotation.*;
+
+public class IsAnnotationType {
+ interface AnnotationPoseur extends Annotation {
+ }
+
+ static int test(Class clazz, boolean expected) {
+ int status = (clazz.isAnnotation() == expected)?0:1;
+
+ if (status == 1) {
+ System.err.println("Unexpected annotation status for " + clazz);
+ }
+ return status;
+ }
+
+ public static void main(String argv[]) {
+ int failures = 0;
+
+ failures += test(String.class, false);
+ failures += test(Enum.class, false);
+ failures += test(java.math.RoundingMode.class, false);
+ // Classes in java.lang.annoation
+ failures += test(Annotation.class, false);
+ failures += test(Retention.class, true);
+ failures += test(RetentionPolicy.class, false);
+ failures += test(Target.class, true);
+ failures += test(AnnotationPoseur.class, false);
+
+ if (failures > 0) {
+ throw new RuntimeException("Unexepcted annotation " +
+ "status detected.");
+ }
+ }
+}
diff --git a/test/java/lang/Class/IsEnum.java b/test/java/lang/Class/IsEnum.java
new file mode 100644
index 0000000..1b4ccb7
--- /dev/null
+++ b/test/java/lang/Class/IsEnum.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4891872 4989735 4990789 5020490
+ * @summary Check isEnum() method
+ * @author Joseph D. Darcy
+ * @compile -source 1.5 IsEnum.java
+ * @run main IsEnum
+ */
+
+import java.lang.annotation.*;
+
+public class IsEnum {
+
+ static int test(Class clazz, boolean expected) {
+ int status = (clazz.isEnum() == expected)?0:1;
+
+ if (status == 1) {
+ System.err.println("Unexpected enum status for " + clazz);
+ }
+ return status;
+ }
+
+ public static void main(String argv[]) {
+ int failures = 0;
+
+ failures += test(IsEnum.class, false);
+ failures += test(String.class, false);
+ failures += test(Enum.class, false);
+ failures += test(java.math.RoundingMode.class, true);
+
+ // Classes in java.lang.annoation
+ failures += test(Annotation.class, false);
+ failures += test(ElementType.class, true);
+ failures += test(Retention.class, false);
+ failures += test(RetentionPolicy.class, true);
+ failures += test(Target.class, false);
+ failures += test(EnumPoseur.class, false);
+
+ // Classes for specialized enum constants aren't enum's
+ failures += test(SpecialEnum.class, true);
+ failures += test(SpecialEnum.RED.getClass(), false);
+ failures += test(SpecialEnum.GREEN.getClass(), true);
+
+ if (failures > 0) {
+ throw new RuntimeException("Unexepcted enum status detected.");
+ }
+ }
+}
+
+enum SpecialEnum {
+ RED {
+ String special() {return "riding hood";}
+ },
+
+ GREEN;
+
+ String special() {return "how was my valley";}
+}
diff --git a/test/java/lang/Class/IsSynthetic.java b/test/java/lang/Class/IsSynthetic.java
new file mode 100644
index 0000000..11950f3
--- /dev/null
+++ b/test/java/lang/Class/IsSynthetic.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5012133
+ * @summary Check Class.isSynthetic method
+ * @author Joseph D. Darcy
+ */
+
+import java.lang.reflect.*;
+
+public class IsSynthetic {
+
+ static class NestedClass {
+ }
+
+ static int test(Class<?> clazz, boolean expected) {
+ if (clazz.isSynthetic() == expected)
+ return 0;
+ else {
+ System.err.println("Unexpected synthetic status for " +
+ clazz.getName() + " expected: " + expected +
+ " got: " + (!expected));
+ return 1;
+ }
+ }
+
+ public static void main(String argv[]) {
+ int failures = 0;
+ class LocalClass {}
+
+ Cloneable clone = new Cloneable() {};
+
+ failures += test(IsSynthetic.class, false);
+ failures += test(java.lang.String.class, false);
+ failures += test(LocalClass.class, false);
+ failures += test(NestedClass.class, false);
+ failures += test(clone.getClass(), false);
+
+ for(Constructor c: Tricky.class.getDeclaredConstructors()) {
+ Class<?>[] paramTypes = c.getParameterTypes();
+ if (paramTypes.length > 0) {
+ System.out.println("Testing class that should be synthetic.");
+ for(Class paramType: paramTypes) {
+ failures += test(paramType, true);
+ }
+ }
+ }
+
+ if (failures != 0)
+ throw new RuntimeException("Test failed with " + failures + " failures.");
+ }
+}
+
+class Tricky {
+ private Tricky() {}
+
+ public static class Nested {
+ Tricky t = new Tricky();
+ }
+}
diff --git a/test/java/lang/Class/TypeCheckMicroBenchmark.java b/test/java/lang/Class/TypeCheckMicroBenchmark.java
new file mode 100644
index 0000000..223ad14
--- /dev/null
+++ b/test/java/lang/Class/TypeCheckMicroBenchmark.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * This is not a regression test, but a micro-benchmark.
+ *
+ * I have run this as follows:
+ *
+ * repeat 5 for f in -client -server; do mergeBench dolphin . jr -dsa -da $f TypeCheckMicroBenchmark.java; done
+ *
+ *
+ * @author Martin Buchholz
+ */
+
+import java.util.*;
+
+public class TypeCheckMicroBenchmark {
+ abstract static class Job {
+ private final String name;
+ Job(String name) { this.name = name; }
+ String name() { return name; }
+ abstract void work() throws Throwable;
+ }
+
+ private static void collectAllGarbage() {
+ final java.util.concurrent.CountDownLatch drained
+ = new java.util.concurrent.CountDownLatch(1);
+ try {
+ System.gc(); // enqueue finalizable objects
+ new Object() { protected void finalize() {
+ drained.countDown(); }};
+ System.gc(); // enqueue detector
+ drained.await(); // wait for finalizer queue to drain
+ System.gc(); // cleanup finalized objects
+ } catch (InterruptedException e) { throw new Error(e); }
+ }
+
+ /**
+ * Runs each job for long enough that all the runtime compilers
+ * have had plenty of time to warm up, i.e. get around to
+ * compiling everything worth compiling.
+ * Returns array of average times per job per run.
+ */
+ private static long[] time0(Job ... jobs) throws Throwable {
+ final long warmupNanos = 10L * 1000L * 1000L * 1000L;
+ long[] nanoss = new long[jobs.length];
+ for (int i = 0; i < jobs.length; i++) {
+ collectAllGarbage();
+ long t0 = System.nanoTime();
+ long t;
+ int j = 0;
+ do { jobs[i].work(); j++; }
+ while ((t = System.nanoTime() - t0) < warmupNanos);
+ nanoss[i] = t/j;
+ }
+ return nanoss;
+ }
+
+ private static void time(Job ... jobs) throws Throwable {
+
+ long[] warmup = time0(jobs); // Warm up run
+ long[] nanoss = time0(jobs); // Real timing run
+ long[] milliss = new long[jobs.length];
+ double[] ratios = new double[jobs.length];
+
+ final String nameHeader = "Method";
+ final String millisHeader = "Millis";
+ final String ratioHeader = "Ratio";
+
+ int nameWidth = nameHeader.length();
+ int millisWidth = millisHeader.length();
+ int ratioWidth = ratioHeader.length();
+
+ for (int i = 0; i < jobs.length; i++) {
+ nameWidth = Math.max(nameWidth, jobs[i].name().length());
+
+ milliss[i] = nanoss[i]/(1000L * 1000L);
+ millisWidth = Math.max(millisWidth,
+ String.format("%d", milliss[i]).length());
+
+ ratios[i] = (double) nanoss[i] / (double) nanoss[0];
+ ratioWidth = Math.max(ratioWidth,
+ String.format("%.3f", ratios[i]).length());
+ }
+
+ String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
+ nameWidth, millisWidth, ratioWidth);
+ String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
+ nameWidth, millisWidth, ratioWidth);
+ System.out.printf(headerFormat, "Method", "Millis", "Ratio");
+
+ // Print out absolute and relative times, calibrated against first job
+ for (int i = 0; i < jobs.length; i++)
+ System.out.printf(format, jobs[i].name(), milliss[i], ratios[i]);
+ }
+
+ private static String keywordValue(String[] args, String keyword) {
+ for (String arg : args)
+ if (arg.startsWith(keyword))
+ return arg.substring(keyword.length() + 1);
+ return null;
+ }
+
+ private static int intArg(String[] args, String keyword, int defaultValue) {
+ String val = keywordValue(args, keyword);
+ return val == null ? defaultValue : Integer.parseInt(val);
+ }
+
+ private static java.util.regex.Pattern patternArg(String[] args,
+ String keyword) {
+ String val = keywordValue(args, keyword);
+ return val == null ? null : java.util.regex.Pattern.compile(val);
+ }
+
+ private static Job[] filter(java.util.regex.Pattern filter,
+ Job[] jobs) {
+ if (filter == null) return jobs;
+ Job[] newJobs = new Job[jobs.length];
+ int n = 0;
+ for (Job job : jobs)
+ if (filter.matcher(job.name()).find())
+ newJobs[n++] = job;
+ // Arrays.copyOf not available in JDK 5
+ Job[] ret = new Job[n];
+ System.arraycopy(newJobs, 0, ret, 0, n);
+ return ret;
+ }
+
+ /**
+ * Usage: [iterations=N] [size=N] [filter=REGEXP]
+ */
+ public static void main(String[] args) throws Throwable {
+ final int iterations = intArg(args, "iterations", 30000);
+ final int size = intArg(args, "size", 1000);
+ final java.util.regex.Pattern filter
+ = patternArg(args, "filter");
+
+ final List<Integer> list = new ArrayList<Integer>();
+ final Random rnd = new Random();
+ for (int i = 0; i < size; i++)
+ list.add(rnd.nextInt());
+ final Class klazz = Integer.class;
+
+ final Job[] jobs = {
+ new Job("toArray(T[])") { void work() {
+ Object[] a = new Integer[0];
+ for (int i = 0; i < iterations; i++) {
+ try { list.toArray(a); }
+ catch (ArrayStoreException ase) {
+ throw new ClassCastException(); }}}},
+ new Job("isInstance") { void work() {
+ for (int i = 0; i < iterations; i++) {
+ for (Object x : list.toArray())
+ if (! (x != null && klazz.isInstance(x)))
+ throw new ClassCastException(); }}},
+ new Job("Class.cast") { void work() {
+ for (int i = 0; i < iterations; i++) {
+ for (Object x : list.toArray())
+ klazz.cast(x); }}},
+ new Job("write into array") { void work() {
+ Object[] a = new Integer[1];
+ for (int i = 0; i < iterations; i++) {
+ for (Object x : list.toArray()) {
+ try { a[0] = x; }
+ catch (ArrayStoreException _) {
+ throw new ClassCastException(); }}}}},
+ new Job("write into dynamic array") { void work() {
+ for (int i = 0; i < iterations; i++) {
+ for (Object x : list.toArray()) {
+ Object[] a = (Object[])
+ java.lang.reflect.Array.newInstance(klazz, 1);
+ try { a[0] = x; }
+ catch (ArrayStoreException _) {
+ throw new ClassCastException(); }}}}}
+ };
+
+ time(filter(filter, jobs));
+ }
+}
diff --git a/test/java/lang/Class/asSubclass/BasicUnit.java b/test/java/lang/Class/asSubclass/BasicUnit.java
new file mode 100644
index 0000000..68cf1c3
--- /dev/null
+++ b/test/java/lang/Class/asSubclass/BasicUnit.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5030212
+ * @summary please add a typesafe cast for Class<?> types
+ * @author gafter
+ *
+ * @compile -Xlint:unchecked -Werror -source 1.5 BasicUnit.java
+ * @run main BasicUnit
+ */
+
+interface Int {
+ void main();
+}
+
+class MyInt implements Int {
+ public void main() {
+ System.out.println("Hello, world!");
+ }
+}
+
+public class BasicUnit {
+ static <T extends Int> T factory(Class<T> c) throws Throwable {
+ return c.newInstance();
+ }
+ public static void main(String[] args) throws Throwable {
+ factory(Class.forName("MyInt").asSubclass(Int.class)).main();
+ }
+}
diff --git a/test/java/lang/Class/forName/InitArg.java b/test/java/lang/Class/forName/InitArg.java
new file mode 100644
index 0000000..12a3be2
--- /dev/null
+++ b/test/java/lang/Class/forName/InitArg.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4131701
+ @summary This is a basic sanity test for the Class.forName
+ variant that the 'whether-initialize' arg.
+ */
+
+class x123 {
+ static {
+ InitArg.x123Initialized = true;
+ }
+}
+
+public class InitArg {
+
+ public static boolean x123Initialized = false;
+
+ public static void main(String[] args) throws Exception {
+ Class c = Class.forName("x123", false,
+ InitArg.class.getClassLoader());
+ if (x123Initialized) {
+ throw new Exception("forName should not run initializer");
+ }
+ Class d = Class.forName("x123", true,
+ InitArg.class.getClassLoader());
+ if (!x123Initialized) {
+ throw new Exception("forName not running initializer");
+ }
+ }
+}
diff --git a/test/java/lang/Class/forName/InvalidNameWithSlash.java b/test/java/lang/Class/forName/InvalidNameWithSlash.java
new file mode 100644
index 0000000..ae31307
--- /dev/null
+++ b/test/java/lang/Class/forName/InvalidNameWithSlash.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4104861
+ @summary forName is accepting methods with slashes
+ @author James Bond/007
+ */
+
+public class InvalidNameWithSlash {
+ public static void main(String[] args) throws Exception {
+ boolean exceptionOccurred = false;
+ try {
+ Class c = Class.forName("java/lang.Object");
+ } catch (Exception e) {
+ exceptionOccurred = true;
+ }
+ if (!exceptionOccurred) {
+ throw new Exception("forName accepting names with slashes?");
+ }
+ }
+}
diff --git a/test/java/lang/Class/forName/NonJavaNames.java b/test/java/lang/Class/forName/NonJavaNames.java
new file mode 100644
index 0000000..5c18179
--- /dev/null
+++ b/test/java/lang/Class/forName/NonJavaNames.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Used by NonJavaNames.sh; needs to be run with a classpath including
+ * test/java/lang/Class/forName/classes
+ */
+
+public class NonJavaNames {
+ public static class Baz {
+ public Baz(){}
+ }
+
+ public static interface myInterface {
+ }
+
+ NonJavaNames.myInterface create(){
+ // With target 1.5, this class's name will include a '+'
+ // instead of a '$'.
+ class Baz2 implements NonJavaNames.myInterface {
+ public Baz2(){}
+ }
+
+ return new Baz2();
+ }
+
+ public static void main(String[] args) throws Exception {
+ NonJavaNames.Baz bz = new NonJavaNames.Baz();
+
+ String name;
+
+ if (Class.forName(name=bz.getClass().getName()) != NonJavaNames.Baz.class) {
+ System.err.println("Class object from forName does not match object.class.");
+ System.err.println("Failures for class ``" + name + "''.");
+ throw new RuntimeException();
+ }
+
+ NonJavaNames.myInterface bz2 = (new NonJavaNames()).create();
+ if (Class.forName(name=bz2.getClass().getName()) != bz2.getClass()) {
+ System.err.println("Class object from forName does not match getClass.");
+ System.err.println("Failures for class ``" + name + "''.");
+ throw new RuntimeException();
+ }
+
+ String goodNonJavaClassNames [] = {
+ ",",
+ "+",
+ "-",
+ "0",
+ "3",
+ // ":", These names won't work under windows.
+ // "<",
+ // ">",
+ "Z",
+ "]"
+ };
+
+ for(String s : goodNonJavaClassNames) {
+ System.out.println("Testing good class name ``" + s + "''");
+ Class.forName(s);
+ }
+
+ String badNonJavaClassNames [] = {
+ ";",
+ "[",
+ "."
+ };
+
+ for(String s : badNonJavaClassNames) {
+ System.out.println("Testing bad class name ``" + s + "''");
+ try {
+ Class.forName(s);
+ } catch (Exception e) {
+ // Expected behavior
+ continue;
+ }
+ throw new RuntimeException("Bad class name ``" + s + "'' accepted.");
+ }
+ }
+}
diff --git a/test/java/lang/Class/forName/NonJavaNames.sh b/test/java/lang/Class/forName/NonJavaNames.sh
new file mode 100644
index 0000000..0071f9e
--- /dev/null
+++ b/test/java/lang/Class/forName/NonJavaNames.sh
@@ -0,0 +1,110 @@
+#
+# Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 4952558
+# @summary Verify names that aren't legal Java names are accepted by forName.
+# @author Joseph D. Darcy
+# @compile -source 1.5 -target 1.5 NonJavaNames.java
+# @run shell NonJavaNames.sh
+
+# This test uses hand-generated class files stored in the ./classes
+# directory. After the renaming done below, those class files have
+# single character names that are legal class names under class file
+# version 49 but *not* legal Java language identifiers; e.g. "3" and
+# "+". First, Z.java is compiled to Z.class using "-target 1.5."
+# Next, to create a test class file, the appropriate name structures
+# within the class files are updated, as is the "Hello world" string
+# the class's main method prints out. If the definition of the
+# semantics of "-target 1.5" changes, the test class files should be
+# regenerated.
+
+# Verify directory context variables are set
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTSRC}" = "" ]
+then
+ echo "TESTSRC not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTCLASSES}" = "" ]
+then
+ echo "TESTCLASSES not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+# All preconditions are met; run the tests
+
+OS=`uname -s`;
+# Set classpath separator
+case "$OS" in
+ Windows* | CYGWIN* )
+ SEP=";"
+ ;;
+
+ * )
+ SEP=":"
+esac
+
+# Copy "hyphen.class" to "-.class"
+
+COPYHYPHEN="cp ${TESTSRC}/classes/hyphen.class ${TESTCLASSES}/-.class"
+$COPYHYPHEN
+
+COPYCOMMA="cp ${TESTSRC}/classes/comma.class ${TESTCLASSES}/,.class"
+$COPYCOMMA
+
+COPYPERIOD="cp ${TESTSRC}/classes/period.class ${TESTCLASSES}/..class"
+$COPYPERIOD
+
+COPYLEFTSQUARE="cp ${TESTSRC}/classes/left-square.class ${TESTCLASSES}/[.class"
+$COPYLEFTSQUARE
+
+COPYRIGHTSQUARE="cp ${TESTSRC}/classes/right-square.class ${TESTCLASSES}/].class"
+$COPYRIGHTSQUARE
+
+COPYPLUS="cp ${TESTSRC}/classes/plus.class ${TESTCLASSES}/+.class"
+$COPYPLUS
+
+COPYSEMICOLON="cp ${TESTSRC}/classes/semicolon.class ${TESTCLASSES}/;.class"
+$COPYSEMICOLON
+
+JAVA="$TESTJAVA/bin/java -classpath ${TESTSRC}/classes${SEP}${TESTCLASSES}"
+
+$JAVA NonJavaNames
+RESULT=$?
+
+case "$RESULT" in
+ 0 )
+ exit 0;
+ ;;
+
+ * )
+ exit 1
+esac
+
diff --git a/test/java/lang/Class/forName/Z.java b/test/java/lang/Class/forName/Z.java
new file mode 100644
index 0000000..661fa44
--- /dev/null
+++ b/test/java/lang/Class/forName/Z.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Source used to generated primordial class file for NonJavaNames
+ * test.
+ */
+public class Z {
+ public static void main(String argv[]) {
+ System.out.println("Hello world.");
+ }
+}
diff --git a/test/java/lang/Class/forName/classes/0.class b/test/java/lang/Class/forName/classes/0.class
new file mode 100644
index 0000000..b5b6c8f
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/0.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/3.class b/test/java/lang/Class/forName/classes/3.class
new file mode 100644
index 0000000..4d183b0
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/3.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/Z.class b/test/java/lang/Class/forName/classes/Z.class
new file mode 100644
index 0000000..cedf4a3
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/Z.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/comma.class b/test/java/lang/Class/forName/classes/comma.class
new file mode 100644
index 0000000..7d21d71
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/comma.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/hyphen.class b/test/java/lang/Class/forName/classes/hyphen.class
new file mode 100644
index 0000000..9ca3213
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/hyphen.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/left-square.class b/test/java/lang/Class/forName/classes/left-square.class
new file mode 100644
index 0000000..8d5009d
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/left-square.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/period.class b/test/java/lang/Class/forName/classes/period.class
new file mode 100644
index 0000000..2581aab
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/period.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/plus.class b/test/java/lang/Class/forName/classes/plus.class
new file mode 100644
index 0000000..32037d7
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/plus.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/right-square.class b/test/java/lang/Class/forName/classes/right-square.class
new file mode 100644
index 0000000..0b61551
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/right-square.class
Binary files differ
diff --git a/test/java/lang/Class/forName/classes/semicolon.class b/test/java/lang/Class/forName/classes/semicolon.class
new file mode 100644
index 0000000..a152408
--- /dev/null
+++ b/test/java/lang/Class/forName/classes/semicolon.class
Binary files differ
diff --git a/test/java/lang/Class/getClasses/Sanity.java b/test/java/lang/Class/getClasses/Sanity.java
new file mode 100644
index 0000000..3e504eb
--- /dev/null
+++ b/test/java/lang/Class/getClasses/Sanity.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4028577
+ @summary Sanity check that Class.getClasses() works.
+ @author Anand Palaniswamy
+ */
+public class Sanity {
+ public class Base {
+ public class BInner { }
+ protected class BProtected { }
+ class BPackage { }
+ }
+
+ public class Derived extends Base {
+ public class DInner { }
+ protected class DProtected { }
+ class DPackage { }
+ }
+
+ public static void main(String[] args) throws Exception {
+ Class[] c = Derived.class.getClasses();
+ if (c.length != 2)
+ throw new Exception("Incorrect number of public classes returned");
+ for (int i = 0; i < c.length; i++) {
+ if (c[i] != Base.BInner.class &&
+ c[i] != Derived.DInner.class)
+ throw new Exception("Garbage in declared classes");
+ }
+ }
+}
diff --git a/test/java/lang/Class/getDeclaredClasses/Sanity.java b/test/java/lang/Class/getDeclaredClasses/Sanity.java
new file mode 100644
index 0000000..6acb891
--- /dev/null
+++ b/test/java/lang/Class/getDeclaredClasses/Sanity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1998-2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4028577 4726689
+ * @summary Sanity check that Class.getDeclaredClasses() works.
+ */
+public class Sanity {
+ static class Toplevel { }
+ class Nested { }
+
+ public static void main(String[] args) throws Exception {
+ class BlockLocal { };
+ new Object() { };
+ Class[] c = Sanity.class.getDeclaredClasses();
+ if (c.length < 2)
+ throw new Exception("Incorrect number of declared classes");
+
+ for (int i = 0; i < c.length; i++) {
+ String name = c[i].getName();
+ System.out.println(name);
+
+ if (c[i] != Nested.class && c[i] != Toplevel.class
+ && !name.matches("\\D\\w*\\$\\d*"))
+ throw new Exception("Unexpected class: " + name);
+ }
+ }
+}
diff --git a/test/java/lang/Class/getDeclaredClasses/TypeTag.java b/test/java/lang/Class/getDeclaredClasses/TypeTag.java
new file mode 100644
index 0000000..7316cf4
--- /dev/null
+++ b/test/java/lang/Class/getDeclaredClasses/TypeTag.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 1998-2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4185857 4726689
+ * @summary The array returned by getDeclaredClasses doesn't have the
+ * array element type tag.
+ */
+public class TypeTag {
+
+ private static class Inner { }
+
+ public static void main(String[] args) throws Exception {
+ Class[] v = null;
+
+ v = Integer.TYPE.getDeclaredClasses();
+ if (v == null || v.length != 0)
+ throw new Exception("Integer.TYPE.getDeclaredClasses is not working");
+ System.out.println("Integer.TYPE: "+ v.toString());
+
+ v = TypeTag.class.getDeclaredClasses();
+ if (v == null)
+ throw new Exception("TypeTag.class.getDeclaredClasses returned null");
+ System.out.println("TypeTag.class: " + v.toString());
+
+ int n = 0;
+ for (int i = 0; i < v.length; i++) {
+ String name = v[i].getName();
+ System.out.print(name);
+
+ if (!name.matches("\\D\\w*\\$\\d*")) {
+ n++;
+ System.out.println(" -- user class");
+ } else {
+ System.out.println();
+ }
+ }
+
+ if (n != 1)
+ throw new Exception("TypeTag.class.getDeclaredClasses found too many classes");
+ }
+}
diff --git a/test/java/lang/Class/getDeclaredField/Exceptions.java b/test/java/lang/Class/getDeclaredField/Exceptions.java
new file mode 100644
index 0000000..96ebf06
--- /dev/null
+++ b/test/java/lang/Class/getDeclaredField/Exceptions.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4319910
+ * @summary Verify that exceptions are thrown as expected.
+ */
+
+public class Exceptions {
+ int f0;
+ public int f1;
+ private int f2;
+ protected int f4;
+
+ private static final String [] npe = {null};
+ private static final String [] nsfe = {"f6"};
+ private static final String [] pass = {"f0", "f1", "f2", "f4"};
+
+ private void test(String s, Class ex) {
+ Throwable t = null;
+ try {
+ getClass().getDeclaredField(s);
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ t = x;
+ }
+ if ((t == null) && (ex != null))
+ throw new RuntimeException("expected " + ex.getName()
+ + " for " + s);
+ else
+ System.out.println(s + " OK");
+ }
+
+ public static void main(String [] args) {
+ Exceptions e = new Exceptions();
+ for (int i = 0; i < npe.length; i++)
+ e.test(npe[i], NullPointerException.class);
+ for (int i = 0; i < nsfe.length; i++)
+ e.test(nsfe[i], NoSuchFieldException.class);
+ for (int i = 0; i < pass.length; i++)
+ e.test(pass[i], null);
+ }
+}
diff --git a/test/java/lang/Class/getDeclaredMethod/Exceptions.java b/test/java/lang/Class/getDeclaredMethod/Exceptions.java
new file mode 100644
index 0000000..d4d75c7
--- /dev/null
+++ b/test/java/lang/Class/getDeclaredMethod/Exceptions.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4319910
+ * @summary Verify that exceptions are thrown as expected.
+ */
+
+public class Exceptions {
+ void m0() {}
+ public void m1() {}
+ private void m2() {}
+ protected void m4() {}
+
+ private static final String [] npe = {null};
+ private static final String [] nsme = {"m6"};
+ private static final String [] pass = {"m0", "m1", "m2", "m4"};
+
+ private void test(String s, Class ex) {
+ Throwable t = null;
+ try {
+ getClass().getDeclaredMethod(s, new Class[] {});
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ t = x;
+ }
+ if ((t == null) && (ex != null))
+ throw new RuntimeException("expected " + ex.getName()
+ + " for " + s);
+ else
+ System.out.println(s + " OK");
+ }
+
+ public static void main(String [] args) {
+ Exceptions e = new Exceptions();
+ for (int i = 0; i < npe.length; i++)
+ e.test(npe[i], NullPointerException.class);
+ for (int i = 0; i < nsme.length; i++)
+ e.test(nsme[i], NoSuchMethodException.class);
+ for (int i = 0; i < pass.length; i++)
+ e.test(pass[i], null);
+ }
+}
diff --git a/test/java/lang/Class/getDeclaringClass/Sanity.java b/test/java/lang/Class/getDeclaringClass/Sanity.java
new file mode 100644
index 0000000..5ecac5e
--- /dev/null
+++ b/test/java/lang/Class/getDeclaringClass/Sanity.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4028577
+ @summary Sanity check that Class.getDeclaringClass() works.
+ @author Anand Palaniswamy
+ */
+public class Sanity {
+ class Nested {
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (Nested.class.getDeclaringClass() != Sanity.class)
+ throw new Exception("Not finding declaring class");
+
+ /* This will pass on old VM's that return null when this
+ * method was unimplemented. But write the test to keep
+ * regression from happening in the current code.
+ */
+ class BlockLocal {
+ };
+
+ if (BlockLocal.class.getDeclaringClass() != null)
+ throw new Exception("Finding declaring class for block local");
+ }
+}
diff --git a/test/java/lang/Class/getEnclosingClass/EnclosingClass.java b/test/java/lang/Class/getEnclosingClass/EnclosingClass.java
new file mode 100644
index 0000000..1b6675c
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/EnclosingClass.java
@@ -0,0 +1,363 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *
+ * @summary Check getEnclosingClass and other methods
+ * @author Peter von der Ah\u00e9
+ *
+ * a) Top level classes
+ * b) Nested classes (static member classes)
+ * c) Inner classes (non-static member classes)
+ * d) Local classes (named classes declared within a method)
+ * e) Anonymous classes
+ */
+
+/*
+ * TODO:
+ * Test annotations
+ * Test Locals in static initializers
+ * Test Locals in methods
+ * Test Locals in constructors
+ * Test interfaces
+ * Test enums
+ * Test method with a String[] argument
+ */
+
+//package
+
+import common.TestMe;
+
+interface MakeClass {
+ Class<?> make();
+}
+
+public class EnclosingClass {
+ public EnclosingClass() {
+ aec = (new Object() {}).getClass();
+ }
+ static class Nested {
+ static class NestedNested {
+ }
+ class NestedInner {
+ }
+ Class<?> nestedLocal0;
+ Class<?> nestedLocal1;
+ Class<?> nestedLocal2;
+ {
+ class NestedLocal0 {};
+ nestedLocal0 = NestedLocal0.class;
+ nestedMethod1();
+ nestedMethod2(null);
+ }
+ void nestedMethod1() {
+ class NestedLocal1 {}
+ nestedLocal1 = NestedLocal1.class;
+ }
+ void nestedMethod2(String[] args) {
+ class NestedLocal2 {}
+ nestedLocal2 = NestedLocal2.class;
+ }
+ Class<?> nestedAnonymous = (new Object() {}).getClass();
+ static enum NestedNestedEnum {
+ }
+ enum NestedInnerEnum {
+ }
+ }
+
+ class Inner {
+ class InnerInner {
+ }
+ Class<?> innerLocal0;
+ Class<?> innerLocal1;
+ Class<?> innerLocal2;
+ {
+ class InnerLocal0 {
+ };
+ innerLocal0 = InnerLocal0.class;
+ innerMethod1();
+ innerMethod2(null);
+ }
+ void innerMethod1() {
+ class InnerLocal1 {}
+ innerLocal1 = InnerLocal1.class;
+ }
+ void innerMethod2(String[] args) {
+ class InnerLocal2 {}
+ innerLocal2 = InnerLocal2.class;
+ }
+ Class<?> innerAnonymous = (new Object() {}).getClass();
+ }
+
+ @TestMe(desc="top level class",
+ encl="null",
+ simple="EnclosingClass",
+ canonical="EnclosingClass")
+ public Class<?> a = EnclosingClass.class;
+
+ @TestMe(desc="nested class within top level class",
+ encl="class EnclosingClass",
+ simple="Nested",
+ canonical="EnclosingClass.Nested")
+ public Class<?> ab = Nested.class;
+ @TestMe(desc="inner class within top level class",
+ encl="class EnclosingClass",
+ simple="Inner",
+ canonical="EnclosingClass.Inner")
+ public Class<?> ac = Inner.class;
+ @TestMe(desc="local class within top level class",
+ encl="class EnclosingClass",
+ simple="Local0",
+ hasCanonical=false)
+ public Class<?> ad0;
+ @TestMe(desc="local class within top level class",
+ encl="class EnclosingClass",
+ simple="Local1",
+ hasCanonical=false)
+ public Class<?> ad1;
+ @TestMe(desc="local class within top level class",
+ encl="class EnclosingClass",
+ simple="Local2",
+ hasCanonical=false)
+ public Class<?> ad2;
+ @TestMe(desc="local class within a top level class static initializer" ,
+ encl="class EnclosingClass",
+ simple="StaticLocal0",
+ hasCanonical=false)
+ public Class<?> sad0;
+ @TestMe(desc="local class within a top level class static method" ,
+ encl="class EnclosingClass",
+ simple="StaticLocal1",
+ hasCanonical=false)
+ public Class<?> sad1;
+ @TestMe(desc="local class within a top level class static method",
+ encl="class EnclosingClass",
+ simple="StaticLocal2",
+ hasCanonical=false)
+ public Class<?> sad2;
+ {
+ class Local0 {
+ class LocalInner {}
+ {
+ class LocalLocal {};
+ dd = LocalLocal.class;
+ de = (new Object() {}).getClass();
+ }
+ };
+ ad0 = Local0.class;
+ dc = Local0.LocalInner.class;
+ new Local0();
+ method1();
+ method2(null);
+ sad0 = staticLocal0;
+ sad1 = staticMethod1();
+ sad2 = staticMethod2(null);
+ }
+ static Class<?> staticLocal0;
+ static {
+ class StaticLocal0 {};
+ staticLocal0 = StaticLocal0.class;
+ }
+ static Class<?> staticMethod1() {
+ class StaticLocal1 {};
+ return StaticLocal1.class;
+ }
+ static Class<?> staticMethod2(String[] args) {
+ class StaticLocal2 {};
+ return StaticLocal2.class;
+ }
+ void method1() {
+ class Local1 {};
+ ad1 = Local1.class;
+ }
+ void method2(String[] args) {
+ class Local2 {};
+ ad2 = Local2.class;
+ }
+ @TestMe(desc="anonymous class within top level class",
+ encl="class EnclosingClass",
+ simple="",
+ hasCanonical=false)
+ public Class<?> ae = (new Object() {}).getClass();
+ @TestMe(desc="anonymous class within top level class constructor",
+ encl="class EnclosingClass",
+ simple="",
+ hasCanonical=false)
+ public Class<?> aec;
+
+ @TestMe(desc="nested class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="NestedNested",
+ canonical="EnclosingClass.Nested.NestedNested")
+ public Class<?> bb = Nested.NestedNested.class;
+ @TestMe(desc="inner class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="NestedInner",
+ canonical="EnclosingClass.Nested.NestedInner")
+ public Class<?> bc = Nested.NestedInner.class;
+ @TestMe(desc="local class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="NestedLocal0",
+ hasCanonical=false)
+ public Class<?> bd0 = (new Nested()).nestedLocal0;
+ @TestMe(desc="local class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="NestedLocal1",
+ hasCanonical=false)
+ public Class<?> bd1 = (new Nested()).nestedLocal1;
+ @TestMe(desc="local class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="NestedLocal2",
+ hasCanonical=false)
+ public Class<?> bd2 = (new Nested()).nestedLocal2;
+ @TestMe(desc="anonymous class within nested class",
+ encl="class EnclosingClass$Nested",
+ simple="",
+ hasCanonical=false)
+ public Class<?> be = (new Nested()).nestedAnonymous;
+
+ @TestMe(desc="nested class within an inner class", encl="", simple="")
+ public Class<?> cb = Void.class; // not legal
+ @TestMe(desc="inner class within an inner class",
+ encl="class EnclosingClass$Inner",
+ simple="InnerInner",
+ canonical="EnclosingClass.Inner.InnerInner")
+ public Class<?> cc = ((new Inner()).new InnerInner()).getClass();
+ @TestMe(desc="local class within an inner class",
+ encl="class EnclosingClass$Inner",
+ simple="InnerLocal0",
+ hasCanonical=false)
+ public Class<?> cd = (new Inner()).innerLocal0;
+ @TestMe(desc="anonymous class within an inner class",
+ encl="class EnclosingClass$Inner",
+ simple="",
+ hasCanonical=false)
+ public Class<?> ce = (new Inner()).innerAnonymous;
+
+ @TestMe(desc="nested class within a local class", encl="", simple="")
+ public Class<?> db = Void.class; // not legal
+ @TestMe(desc="inner class within a local class",
+ encl="class EnclosingClass$1Local0",
+ simple="LocalInner",
+ hasCanonical=false)
+ public Class<?> dc; // initialized above
+ @TestMe(desc="local class within a local class",
+ encl="class EnclosingClass$1Local0",
+ simple="LocalLocal",
+ hasCanonical=false)
+ public Class<?> dd; // initialized above
+ @TestMe(desc="anonymous class within a local class",
+ encl="class EnclosingClass$1Local0",
+ simple="",
+ hasCanonical=false)
+ public Class<?> de; // initialized above
+
+ @TestMe(desc="nested class within an anonymous class", encl="", simple="")
+ public Class<?> eb = Void.class; // not legal
+ @TestMe(desc="inner class within an anonymous class",
+ encl="class EnclosingClass$3",
+ simple="AnonymousInner",
+ hasCanonical=false)
+ public Class<?> ec = new MakeClass() {
+ class AnonymousInner {}
+ public Class<?> make() { return AnonymousInner.class; }
+ }.make();
+ @TestMe(desc="local class within an anonymous class",
+ encl="class EnclosingClass$4",
+ simple="AnonymousLocal",
+ hasCanonical=false)
+ public Class<?> ed = new MakeClass() {
+ Class<?> c;
+ {
+ class AnonymousLocal {}
+ c = AnonymousLocal.class;
+ }
+ public Class<?> make() { return c; }
+ }.make();
+ @TestMe(desc="anonymous class within an anonymous class",
+ encl="class EnclosingClass$5",
+ simple="",
+ hasCanonical=false)
+ public Class<?> ee = new MakeClass() {
+ Class<?> c;
+ {
+ c = new Object() {}.getClass();
+ }
+ public Class<?> make() { return c; }
+ }.make();
+
+ @TestMe(desc="the primitive boolean type",
+ encl="null",
+ simple="boolean",
+ canonical="boolean")
+ public Class<?> booleanClass = boolean.class;
+
+ @TestMe(desc="the primitive char type",
+ encl="null",
+ simple="char",
+ canonical="char")
+ public Class<?> charClass = char.class;
+
+ @TestMe(desc="the primitive byte type",
+ encl="null",
+ simple="byte",
+ canonical="byte")
+ public Class<?> byteClass = byte.class;
+
+ @TestMe(desc="the primitive short type",
+ encl="null",
+ simple="short",
+ canonical="short")
+ public Class<?> shortClass = short.class;
+
+ @TestMe(desc="the primitive int type",
+ encl="null",
+ simple="int",
+ canonical="int")
+ public Class<?> intClass = int.class;
+
+ @TestMe(desc="the primitive long type",
+ encl="null",
+ simple="long",
+ canonical="long")
+ public Class<?> longClass = long.class;
+
+ @TestMe(desc="the primitive float type",
+ encl="null",
+ simple="float",
+ canonical="float")
+ public Class<?> floatClass = float.class;
+
+ @TestMe(desc="the primitive double type",
+ encl="null",
+ simple="double",
+ canonical="double")
+ public Class<?> doubleClass = double.class;
+
+ @TestMe(desc="the primitive void type",
+ encl="null",
+ simple="void",
+ canonical="void")
+ public Class<?> voidClass = void.class;
+
+}
diff --git a/test/java/lang/Class/getEnclosingClass/EnclosingClassTest.java b/test/java/lang/Class/getEnclosingClass/EnclosingClassTest.java
new file mode 100644
index 0000000..a2be80b
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/EnclosingClassTest.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4992173 4992170
+ *
+ * @run shell make_src.sh
+ * @run shell build.sh
+ * @run main/othervm -esa -ea EnclosingClassTest
+ *
+ * @summary Check getEnclosingClass and other methods
+ * @author Peter von der Ah\u00e9
+ */
+
+/*
+ * We have five kinds of classes:
+ * a) Top level classes
+ * b) Nested classes (static member classes)
+ * c) Inner classes (non-static member classes)
+ * d) Local classes (named classes declared within a method)
+ * e) Anonymous classes
+ *
+ * Each one can be within a package or not.
+ * Kinds b-e can/must be within kinds a-e.
+ * This gives us a three dimensional space:
+ * 1. dimension: b-e
+ * 2. dimension: a-e
+ * 3. dimension: packages
+ *
+ * We make a two dimensional matrix of (b-e)x(a-e) and change the
+ * package configuration on that:
+ *
+ * b c d e
+ * a x x x x
+ * b x x x x
+ * c o x x x where o means "not legal"
+ * d o x x x
+ * e o x x x
+ */
+
+import java.util.List;
+import java.util.LinkedList;
+import java.lang.reflect.Field;
+import common.TestMe;
+
+public class EnclosingClassTest {
+ static void info(Class<?> c, Class<?> encClass, String desc) {
+ if (!"".equals(desc))
+ System.out.println(desc + ":");
+ System.out.println(c);
+ System.out.println("\tis enclosed by:\t\t" + encClass);
+ System.out.println("\thas simple name:\t`" +
+ c.getSimpleName() + "'");
+ System.out.println("\thas canonical name:\t`" +
+ c.getCanonicalName() + "'");
+ }
+
+ static void match(String actual, String expected) {
+ assert((actual == null && expected == null) || actual.equals(expected));
+ System.out.println("\t`" +
+ actual + "' matches expected `" +
+ expected + "'");
+ }
+
+ static void check(Class<?> c, Class<?> enc,
+ String encName, String encNameExpected,
+ String simpleName, String simpleNameExpected,
+ String canonicalName, String canonicalNameExpected) {
+ match(encName, encNameExpected);
+ match(simpleName, simpleNameExpected);
+ match(canonicalName, canonicalNameExpected);
+ }
+
+ static void testClass(Class<?> c, TestMe annotation, Field f) {
+ if (Void.class.equals(c))
+ return;
+ Class<?> encClass = c.getEnclosingClass();
+ c.getEnclosingMethod(); // make sure it does not crash
+ c.getEnclosingConstructor(); // make sure it does not crash
+ info(c, encClass, annotation.desc());
+ check(c, encClass,
+ ""+encClass, annotation.encl(),
+ c.getSimpleName(), annotation.simple(),
+ c.getCanonicalName(),
+ annotation.hasCanonical() ? annotation.canonical() : null);
+ if (void.class.equals(c))
+ return;
+ Class<?> array = java.lang.reflect.Array.newInstance(c, 0).getClass();
+ check(array, array.getEnclosingClass(),
+ "", "",
+ array.getSimpleName(), annotation.simple()+"[]",
+ array.getCanonicalName(),
+ annotation.hasCanonical() ? annotation.canonical()+"[]" : null);
+ }
+
+ static void test(Object tests) {
+ for (Field f : tests.getClass().getFields()) {
+ TestMe annotation = f.getAnnotation(TestMe.class);
+ if (annotation != null) {
+ try {
+ testClass((Class<?>)f.get(tests), annotation, f);
+ } catch (AssertionError ex) {
+ System.err.println("Error in " +
+ tests.getClass().getName() +
+ "." + f.getName());
+ throw ex;
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ }
+ public static void main(String[] args) {
+ test(new EnclosingClass());
+ test(new pkg1.EnclosingClass());
+ test(new pkg1.pkg2.EnclosingClass());
+ }
+}
diff --git a/test/java/lang/Class/getEnclosingClass/T4992170.java b/test/java/lang/Class/getEnclosingClass/T4992170.java
new file mode 100644
index 0000000..6304377
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/T4992170.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4992170
+ *
+ * @run main/othervm -esa -ea T4992170
+ *
+ * @summary enclosing type parameter missing in anonymous and local classes
+ * @author Neal Gafter
+ */
+
+import java.lang.reflect.*;
+
+class A<T> {
+ Object o = new Object() {
+ public T t;
+ };
+}
+
+public class T4992170 {
+ public static void main(String[] args) throws NoSuchFieldException {
+ Type t = new A<Integer>().o.getClass().getField("t").getGenericType();
+ if (!(t instanceof TypeVariable))
+ throw new Error("" + t);
+ }
+}
diff --git a/test/java/lang/Class/getEnclosingClass/build.sh b/test/java/lang/Class/getEnclosingClass/build.sh
new file mode 100644
index 0000000..29099af
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/build.sh
@@ -0,0 +1,41 @@
+#
+# Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# -*- shell-script -*-
+#
+# @summary Check getEnclosingClass and other methods
+# @author Peter von der Ahé
+
+OS=`uname -s`;
+case "${OS}" in
+ Windows* | CYGWIN* )
+ SEP=";"
+ ;;
+
+ * )
+ SEP=":"
+ ;;
+esac
+
+JAVAC=${TESTJAVA}/bin/javac
+${JAVAC} -d ${TESTCLASSES} -sourcepath ${TESTSRC}${SEP}. ${TESTSRC}/EnclosingClassTest.java
diff --git a/test/java/lang/Class/getEnclosingClass/common/TestMe.java b/test/java/lang/Class/getEnclosingClass/common/TestMe.java
new file mode 100644
index 0000000..2425c36
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/common/TestMe.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @summary Check getEnclosingClass and other methods
+ * @author Peter von der Ah\u00e9
+ */
+
+package common;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestMe {
+ String desc();
+ String encl();
+ String simple();
+ boolean hasCanonical() default true;
+ String canonical() default "";
+}
diff --git a/test/java/lang/Class/getEnclosingClass/make_src.sh b/test/java/lang/Class/getEnclosingClass/make_src.sh
new file mode 100644
index 0000000..ee61ac8
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingClass/make_src.sh
@@ -0,0 +1,40 @@
+#
+# Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# -*- shell-script -*-
+# @summary Check getEnclosingClass and other methods
+# @author Peter von der Ahé
+
+rm -rf pkg1
+mkdir pkg1
+mkdir -p pkg1/pkg2
+
+sed '
+s/canonical="EnclosingClass/canonical="pkg1.EnclosingClass/g;
+s/"class EnclosingClass/"class pkg1.EnclosingClass/g;
+s/\/\/package/package pkg1;/g' < ${TESTSRC}/EnclosingClass.java > pkg1/EnclosingClass.java
+
+sed '
+s/canonical="EnclosingClass/canonical="pkg1.pkg2.EnclosingClass/g;
+s/"class EnclosingClass/"class pkg1.pkg2.EnclosingClass/g;
+s/\/\/package/package pkg1.pkg2;/g' < ${TESTSRC}/EnclosingClass.java > pkg1/pkg2/EnclosingClass.java
diff --git a/test/java/lang/Class/getEnclosingConstructor/EnclosingConstructorTests.java b/test/java/lang/Class/getEnclosingConstructor/EnclosingConstructorTests.java
new file mode 100644
index 0000000..fe963fb
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingConstructor/EnclosingConstructorTests.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4962341
+ * @summary Check getEnclosingMethod method
+ * @author Joseph D. Darcy
+ */
+
+import java.lang.reflect.Constructor;
+import java.lang.annotation.*;
+
+public class EnclosingConstructorTests {
+ static Class<?> anonymousClass;
+ static Class<?> localClass;
+ static Class<?> anotherLocalClass;
+
+ static {
+ Cloneable c = new Cloneable() {}; // anonymous cloneable
+ anonymousClass = c.getClass();
+ }
+
+ @ConstructorDescriptor("EnclosingConstructorTests()")
+ EnclosingConstructorTests() {
+ class Local {};
+ Local l = new Local();
+ localClass = l.getClass();
+ }
+
+
+ @ConstructorDescriptor("private EnclosingConstructorTests(int)")
+ private EnclosingConstructorTests(int i) {
+ class Local {};
+ Local l = new Local();
+ anotherLocalClass = l.getClass();
+ }
+
+
+ static int examine(Class enclosedClass, String constructorSig) {
+ Constructor c = enclosedClass.getEnclosingConstructor();
+ if (c == null && constructorSig == null)
+ return 0;
+
+ if (c != null &&
+ c.getAnnotation(ConstructorDescriptor.class).value().equals(constructorSig))
+ return 0; // everything is okay
+ else {
+ System.err.println("\nUnexpected constructor value; expected:\t" + constructorSig +
+ "\ngot:\t" + c);
+ return 1;
+ }
+ }
+
+
+ public static void main(String argv[]) {
+ int failures = 0;
+ class StaticLocal {};
+ EnclosingConstructorTests ect = new EnclosingConstructorTests();
+ ect = new EnclosingConstructorTests(5);
+
+ failures += examine(StaticLocal.class,
+ null);
+
+ failures += examine(localClass,
+ "EnclosingConstructorTests()");
+
+ failures += examine(anotherLocalClass,
+ "private EnclosingConstructorTests(int)");
+
+ failures += examine(anonymousClass,
+ null);
+
+ if (failures > 0)
+ throw new RuntimeException("Test failed.");
+ }
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface ConstructorDescriptor {
+ String value();
+}
diff --git a/test/java/lang/Class/getEnclosingMethod/EnclosingMethodTests.java b/test/java/lang/Class/getEnclosingMethod/EnclosingMethodTests.java
new file mode 100644
index 0000000..88f7c33
--- /dev/null
+++ b/test/java/lang/Class/getEnclosingMethod/EnclosingMethodTests.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4962341
+ * @summary Check getEnclosingMethod method
+ * @author Joseph D. Darcy
+ */
+
+import java.lang.reflect.Method;
+import java.lang.annotation.*;
+
+public class EnclosingMethodTests {
+ static Class<?> anonymousClass;
+
+ static {
+ Cloneable c = new Cloneable() {}; // anonymous cloneable
+ anonymousClass = c.getClass();
+ }
+
+ EnclosingMethodTests() {}
+
+ @MethodDescriptor("java.lang.Class EnclosingMethodTests.getLocalClass(Object o)")
+ Class getLocalClass(Object o) {
+ class Local {};
+ Local l = new Local();
+ return l.getClass();
+ }
+
+ static int examine(Class enclosedClass, String methodSig) {
+ Method m = enclosedClass.getEnclosingMethod();
+ if (m == null && methodSig == null)
+ return 0;
+
+ if (m != null &&
+ m.getAnnotation(MethodDescriptor.class).value().equals(methodSig))
+ return 0; // everything is okay
+ else {
+ System.err.println("\nUnexpected method value; expected:\t" + methodSig +
+ "\ngot:\t" + m);
+ return 1;
+ }
+ }
+
+ @MethodDescriptor("public static void EnclosingMethodTests.main(java.lang.String[])")
+ public static void main(String argv[]) {
+ int failures = 0;
+ class StaticLocal {};
+
+ failures += examine(StaticLocal.class,
+ "public static void EnclosingMethodTests.main(java.lang.String[])");
+
+ failures += examine( (new EnclosingMethodTests()).getLocalClass(null),
+ "java.lang.Class EnclosingMethodTests.getLocalClass(Object o)");
+
+ failures += examine(EnclosingMethodTests.class, null);
+
+ failures += examine(anonymousClass, null);
+
+ if (failures > 0)
+ throw new RuntimeException("Test failed.");
+ }
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface MethodDescriptor {
+ String value();
+}
diff --git a/test/java/lang/Class/getField/Exceptions.java b/test/java/lang/Class/getField/Exceptions.java
new file mode 100644
index 0000000..9eb3285
--- /dev/null
+++ b/test/java/lang/Class/getField/Exceptions.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4319910
+ * @summary Verify that exceptions are thrown as expected.
+ */
+
+public class Exceptions {
+ private static boolean ok = true;
+
+ int f0;
+ public int f1;
+ private int f2;
+ protected int f4;
+
+ private static final String [] npe = {null};
+ private static final String [] nsfe = {"f0", "f2", "f4", "f6"};
+ private static final String [] pass = {"f1"};
+
+ private void test(String s, Class ex) {
+ Throwable t = null;
+ try {
+ getClass().getField(s);
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ t = x;
+ }
+ if ((t == null) && (ex != null)) {
+ ok = false;
+ System.out.println("expected " + ex.getName() + " for " + s
+ + " -- FAILED");
+ } else {
+ System.out.println(s + " -- OK");
+ }
+ }
+
+ public static void main(String [] args) {
+ Exceptions e = new Exceptions();
+ for (int i = 0; i < npe.length; i++)
+ e.test(npe[i], NullPointerException.class);
+ for (int i = 0; i < nsfe.length; i++)
+ e.test(nsfe[i], NoSuchFieldException.class);
+ for (int i = 0; i < pass.length; i++)
+ e.test(pass[i], null);
+ if (!ok)
+ throw new RuntimeException("some tests failed");
+ }
+}
diff --git a/test/java/lang/Class/getMethod/Exceptions.java b/test/java/lang/Class/getMethod/Exceptions.java
new file mode 100644
index 0000000..39b5223
--- /dev/null
+++ b/test/java/lang/Class/getMethod/Exceptions.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4319910
+ * @summary Verify that exceptions are thrown as expected.
+ */
+
+public class Exceptions {
+ void m0() {}
+ public void m1() {}
+ private void m2() {}
+ protected void m4() {}
+
+ private static final String [] npe = {null};
+ private static final String [] nsme = {"m0", "m2", "m4", "m6"};
+ private static final String [] pass = {"m1"};
+
+ private void test(String s, Class ex) {
+ Throwable t = null;
+ try {
+ getClass().getMethod(s, new Class[] {});
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass()))
+ t = x;
+ }
+ if ((t == null) && (ex != null))
+ throw new RuntimeException("expected " + ex.getName()
+ + " for " + s);
+ else
+ System.out.println(s + " OK");
+ }
+
+ public static void main(String [] args) {
+ Exceptions e = new Exceptions();
+ for (int i = 0; i < npe.length; i++)
+ e.test(npe[i], NullPointerException.class);
+ for (int i = 0; i < nsme.length; i++)
+ e.test(nsme[i], NoSuchMethodException.class);
+ for (int i = 0; i < pass.length; i++)
+ e.test(pass[i], null);
+ }
+}
diff --git a/test/java/lang/Class/getMethod/NullInParamList.java b/test/java/lang/Class/getMethod/NullInParamList.java
new file mode 100644
index 0000000..ccb6253
--- /dev/null
+++ b/test/java/lang/Class/getMethod/NullInParamList.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4684974
+ * @summary Verify that NoSuchMethodException is thrown.
+ */
+
+import java.lang.reflect.Method;
+
+class A {
+ public void m(Object o) {}
+}
+
+public class NullInParamList {
+ public static void main(String [] args) {
+ try {
+ Class [] ca = {null};
+ Method m = A.class.getMethod("m", ca);
+ } catch (NoSuchMethodException x) {
+ return;
+ }
+ throw new RuntimeException("FAIL: expected NoSuchMethodException");
+ }
+}
diff --git a/test/java/lang/Class/getMethods/NonPublicStaticInitializer.java b/test/java/lang/Class/getMethods/NonPublicStaticInitializer.java
new file mode 100644
index 0000000..acdef06
--- /dev/null
+++ b/test/java/lang/Class/getMethods/NonPublicStaticInitializer.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4187388
+ @summary <clinit> in interfaces need not be public
+*/
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+interface TestedInterface {
+ String s = System.getProperty("Test");
+
+ void foo();
+ void bar();
+}
+
+
+public class NonPublicStaticInitializer {
+ public static void main(String args[]) throws Exception {
+ Method m[] = TestedInterface.class.getMethods();
+ for (int i = 0; i < m.length; i++) {
+ System.out.println("Found: " +
+ Modifier.toString(m[i].getModifiers()) +
+ " " + m[i].getName());
+ if (m[i].getName().equals("<clinit>")) {
+ throw new Exception("Shouldn't have found <clinit>");
+ }
+ }
+ }
+}
diff --git a/test/java/lang/Class/getMethods/StarInheritance.java b/test/java/lang/Class/getMethods/StarInheritance.java
new file mode 100644
index 0000000..6ac7c93
--- /dev/null
+++ b/test/java/lang/Class/getMethods/StarInheritance.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4654698
+ * @summary Verify that expected methods are returned for star inheritance.
+ */
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+// D.m
+interface A1 extends B1, C1 {}
+interface B1 extends D1 {}
+interface C1 extends D1 {}
+interface D1 { void m(); }
+
+// A.m
+interface A2 extends B2, C2 { void m(); }
+interface B2 extends D2 {}
+interface C2 extends D2 {}
+interface D2 { void m(); }
+
+// B.m, C.m
+interface A3 extends B3, C3 {}
+interface B3 extends D3 { void m(); }
+interface C3 extends D3 { void m(); }
+interface D3 { void m() ; }
+
+// B.m, D.m
+interface A4 extends B4, C4 {}
+interface B4 extends D4 { void m(); }
+interface C4 extends D4 {}
+interface D4 { void m(); }
+
+public class StarInheritance {
+ private static int n = 1;
+
+ private static void test(Method [] ma, ArrayList expect) {
+ System.out.println("Test " + n++);
+
+ if (expect.size() != ma.length) {
+ System.err.println(" found methods: " + Arrays.asList(ma));
+ System.err.println(" expected locations: " + expect);
+ throw new RuntimeException("found = " + ma.length
+ +"; expected = " + expect.size());
+ }
+
+ for (int i = 0; i < ma.length; i++) {
+ Method m = ma[i];
+ System.out.println(" " + m.toString());
+ int n;
+ if (m.getName().equals("m")
+ && (n = expect.indexOf(m.getDeclaringClass())) != -1) {
+ expect.remove(n);
+ } else {
+ throw new RuntimeException("unable to locate method in class: "
+ + m.getDeclaringClass());
+ }
+ }
+ }
+
+ public static void main(String [] args) {
+ Class [] l1 = {D1.class};
+ test(A1.class.getMethods(), new ArrayList(Arrays.asList(l1)));
+
+ Class [] l2 = {A2.class};
+ test(A2.class.getMethods(), new ArrayList(Arrays.asList(l2)));
+
+ Class [] l3 = {B3.class, C3.class};
+ test(A3.class.getMethods(), new ArrayList(Arrays.asList(l3)));
+
+ Class [] l4 = {B4.class, D4.class};
+ test(A4.class.getMethods(), new ArrayList(Arrays.asList(l4)));
+ }
+}
diff --git a/test/java/lang/Class/getModifiers/ForInnerClass.java b/test/java/lang/Class/getModifiers/ForInnerClass.java
new file mode 100644
index 0000000..4b15a7e
--- /dev/null
+++ b/test/java/lang/Class/getModifiers/ForInnerClass.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4109635
+ @summary For an inner class, the access bits must come from the
+ InnerClasses attribute, not from the class block's access.
+ Note however that the VM should not rely on these access
+ flags from the attribute!
+ */
+import java.lang.reflect.Modifier;
+public class ForInnerClass {
+ private class Inner {
+ }
+
+ protected class Protected {
+ }
+
+ public static void main(String[] args) throws Exception {
+ /* We are not testing for the ACC_SUPER bug, so strip we strip
+ * synchorized. */
+
+ int m = 0;
+
+ m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
+ if (m != Modifier.PRIVATE)
+ throw new Exception("Access bits for innerclass not from " +
+ "InnerClasses attribute");
+
+ m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
+ if (m != Modifier.PROTECTED)
+ throw new Exception("Protected inner class wronged modifiers");
+ }
+}
diff --git a/test/java/lang/Class/getModifiers/ForStaticInnerClass.java b/test/java/lang/Class/getModifiers/ForStaticInnerClass.java
new file mode 100644
index 0000000..4107418
--- /dev/null
+++ b/test/java/lang/Class/getModifiers/ForStaticInnerClass.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4163105
+ @summary VM loses static modifier of inner class.
+ */
+
+import java.lang.reflect.Modifier;
+
+public class ForStaticInnerClass {
+ static class Static {
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (!Modifier.isStatic(Static.class.getModifiers()))
+ throw new Exception("VM lost static modifier of innerclass.");
+ }
+}
diff --git a/test/java/lang/Class/getModifiers/ResolveFrom.java b/test/java/lang/Class/getModifiers/ResolveFrom.java
new file mode 100644
index 0000000..9425433
--- /dev/null
+++ b/test/java/lang/Class/getModifiers/ResolveFrom.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4127549
+ @summary getModifiers should resolve constant pool entries from
+ its own class.
+ @author James Bond
+ */
+import java.lang.reflect.Modifier;
+public class ResolveFrom {
+ private class Inner {
+ int i;
+ }
+
+ public static void main(String argv[]) throws Exception {
+ int m = ResolveFrom.class.getModifiers();
+ System.out.println("ResolveFrom has modifiers = " +
+ Modifier.toString(m));
+ }
+}
diff --git a/test/java/lang/Class/getModifiers/StripACC_SUPER.java b/test/java/lang/Class/getModifiers/StripACC_SUPER.java
new file mode 100644
index 0000000..3a6c660
--- /dev/null
+++ b/test/java/lang/Class/getModifiers/StripACC_SUPER.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4109635
+ @summary VM adds ACC_SUPER bit to access flags of a class. This must
+ be stripped by the Class.getModifiers method, or else this
+ shows up as though the class is synchronized and that doesn't
+ make any sense.
+ @author Anand Palaniswamy
+ */
+public class StripACC_SUPER {
+ public static void main(String[] args) throws Exception {
+ int access = StripACC_SUPER.class.getModifiers();
+ if (java.lang.reflect.Modifier.isSynchronized(access))
+ throw new Exception("ACC_SUPER bit is not being stripped");
+ }
+}