file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
P2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/QualifiedAccess/pack1/P2.java
/* * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * Support class for QualifiedAccess tests. */ package pack1; class P2 { public int privatei = 0; }
1,166
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
P1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/QualifiedAccess/pack1/P1.java
/* * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * Support class for QualifiedAccess tests. */ package pack1; public class P1 { public P1() {} protected P1(String s) {} public P2 p2 = new P2(); // Not accessible outside package 'pack1'. class P3 { // Cannot be accessed via qualified name from 'P3' // outside of 'pack1', as 'P3' is not accessible. public class P4 { // Not accessible outside package 'pack1'. class P5 {} } } static class Foo { public static class Bar {} } public Foo a[] = null; protected static class Q { protected Q (String s) {} } protected static class R { private static class S { public static class T {} } } }
1,806
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnVariable.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnVariable.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnVariable.java * @compile/fail -Werror WarnVariable.java * @compile/fail -Werror -source 1.4 -nowarn WarnVariable.java * @compile/fail -Werror -nowarn WarnVariable.java * @compile/fail -Werror -Xlint:none WarnVariable.java */ public class WarnVariable { public static void main(String... args) { System.out.println(sun.misc.FloatConsts.POSITIVE_INFINITY); } }
1,590
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnWildcard.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnWildcard.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnWildcard.java * @compile/fail -Werror WarnWildcard.java * @compile/fail -Werror -source 1.4 -nowarn WarnWildcard.java * @compile/fail -Werror -nowarn WarnWildcard.java * @compile/fail -Werror -Xlint:none WarnWildcard.java */ public class WarnWildcard { java.util.Collection<? extends sun.misc.FloatConsts> x; }
1,530
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnImport.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnImport.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnImport.java * @compile/fail -Werror WarnImport.java * @compile/fail -Werror -source 1.4 -nowarn WarnImport.java * @compile/fail -Werror -nowarn WarnImport.java * @compile/fail -Werror -Xlint:none WarnImport.java */ import sun.misc.VM; public class WarnImport {}
1,478
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnMethod.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnMethod.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnMethod.java * @compile/fail -Werror WarnMethod.java * @compile/fail -Werror -source 1.4 -nowarn WarnMethod.java * @compile/fail -Werror -nowarn WarnMethod.java * @compile/fail -Werror -Xlint:none WarnMethod.java */ public class WarnMethod { public static void main(String... args) { System.out.println(sun.misc.VM.getFinalRefCount()); } }
1,570
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnClass.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnClass.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnClass.java * @compile/fail -Werror WarnClass.java * @compile/fail -Werror -source 1.4 -nowarn WarnClass.java * @compile/fail -Werror -nowarn WarnClass.java * @compile/fail -Werror -Xlint:none WarnClass.java */ public class WarnClass extends sun.misc.Lock {}
1,473
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WarnStaticImport.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/proprietary/WarnStaticImport.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6380059 * @summary Emit warnings for proprietary packages in the boot class path * @author Peter von der Ah\u00e9 * @compile WarnStaticImport.java * @compile/fail -Werror WarnStaticImport.java * @compile/fail -Werror -source 1.4 -nowarn WarnStaticImport.java * @compile/fail -Werror -nowarn WarnStaticImport.java * @compile/fail -Werror -Xlint:none WarnStaticImport.java */ import static sun.misc.VM.getFinalRefCount; public class WarnStaticImport {}
1,538
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
InterfaceAndInnerClsCtor.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassModifiers/InterfaceAndInnerClsCtor.java
/* * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 4221648 * @summary If an interface has an inner class, the constructor for that inner * class must be accessible to the interface, regardless of whether it is * explicitly declared private. * * @clean InterfaceAndInnerClsCtor * @compile InterfaceAndInnerClsCtor.java */ public interface InterfaceAndInnerClsCtor { // All interface memebers are implicitly public. Hence, there is no need to // have other inner classes with different access levels. public static class Inner { // A constructor for each of the possible access levels. public Inner(boolean b) {} Inner(char c) {} protected Inner(int i) {} private Inner() {} } // Verify that all of the constructors are accessible at compile time. public final static Inner i0 = new Inner(true); public final static Inner i1 = new Inner('a'); public final static Inner i2 = new Inner(7); public final static Inner i3 = new Inner(); }
2,039
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
StaticQualifiedNew.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/staticQualifiedNew/StaticQualifiedNew.java
/* * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4295650 * @summary Verify that qualified 'new' of static class is forbidden. * @author maddox (after gbracha) * * @compile/fail StaticQualifiedNew.java */ import p2.X; class StaticQualifiedNew extends X { X.M m2 = new X().new M(); }
1,315
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
X.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/staticQualifiedNew/p2/X.java
/* * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package p2; public class X { static public class M { public M(){} } }
1,133
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadUnderscoreLiterals.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/literals/BadUnderscoreLiterals.java
/* * @test /nodynamiccopyright/ * @bug 6860973 * @summary Project Coin: underscores in literals * * @compile/fail BadUnderscoreLiterals.java * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java * * @compile/fail -source 6 BadUnderscoreLiterals.java * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadUnderscoreLiterals.java */ public class BadUnderscoreLiterals { int valid = 1_1; // valid literal; illegal in -source 6 // test zero int z1 = _0; // valid (but undefined) variable int z2 = 0_; // trailing underscore // test simple (decimal) integers int i1 = _1_2_3; // valid (but undefined) variable int i2 = 1_2_3_; // trailing underscore // test binary integers int b1 = 0b_0; // leading underscore after radix int b2 = 0b0_; // trailing underscore // test hexadecimal integers int x1 = 0x_0; // leading underscore after radix int x2 = 0x0_; // trailing underscore // test floating point numbers float f1 = 0_.1; // trailing underscore before decimal point float f2 = 0._1; // leading underscore after decimal point float f3 = 0.1_; // trailing underscore float f4 = 0.1_e0; // trailing underscore before exponent float f5 = 0e_1; // leading underscore in exponent float f6 = 0e1_; // trailing underscore in exponent // hexadecimal floating point float xf1 = 0x_0.1p0; // leading underscore after radix float xf2 = 0x0_.1p0; // trailing underscore before decimal point float xf3 = 0x0._1p0; // leading underscore after decimal point float xf4 = 0x0.1_p0; // trailing underscore before exponent float xf5 = 0x0p_1; // leading underscore after exponent float xf6 = 0x0p1_; // trailing underscore }
2,028
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BinaryLiterals.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/literals/BinaryLiterals.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6860965 * @summary Project Coin: binary literals */ public class BinaryLiterals { public static void main(String... args) throws Exception { new BinaryLiterals().run(); } public void run() throws Exception { test(0, 0B0); test(1, 0B1); test(2, 0B10); test(3, 0B11); test(0, 0b0); test(1, 0b1); test(2, 0b10); test(3, 0b11); test(-0, -0b0); test(-1, -0b1); test(-2, -0b10); test(-3, -0b11); test(-1, 0b11111111111111111111111111111111); test(-2, 0b11111111111111111111111111111110); test(-3, 0b11111111111111111111111111111101); test( 1, -0b11111111111111111111111111111111); test( 2, -0b11111111111111111111111111111110); test( 3, -0b11111111111111111111111111111101); test(0, 0b00); test(1, 0b001); test(2, 0b00010); test(3, 0b000011); // aaaabbbbccccddddeeeeffffgggghhhh test( 0x10, 0b10000); test( 0x100, 0b100000000); test( 0x10000, 0b10000000000000000); test(0x80000000, 0b10000000000000000000000000000000); test(0xffffffff, 0b11111111111111111111111111111111); test(0L, 0b0L); test(1L, 0b1L); test(2L, 0b10L); test(3L, 0b11L); test(0, 0b00L); test(1, 0b001L); test(2, 0b00010L); test(3, 0b000011L); // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp test( 0x10L, 0b10000L); test( 0x100L, 0b100000000L); test( 0x10000L, 0b10000000000000000L); test( 0x80000000L, 0b10000000000000000000000000000000L); test( 0xffffffffL, 0b11111111111111111111111111111111L); test(0x8000000000000000L, 0b1000000000000000000000000000000000000000000000000000000000000000L); test(0xffffffffffffffffL, 0b1111111111111111111111111111111111111111111111111111111111111111L); test(0l, 0b0l); test(1l, 0b1l); test(2l, 0b10l); test(3l, 0b11l); test(0, 0b00l); test(1, 0b001l); test(2, 0b00010l); test(3, 0b000011l); // aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp test( 0x10l, 0b10000l); test( 0x100l, 0b100000000l); test( 0x10000l, 0b10000000000000000l); test( 0x80000000l, 0b10000000000000000000000000000000l); test( 0xffffffffl, 0b11111111111111111111111111111111l); test(0x8000000000000000l, 0b1000000000000000000000000000000000000000000000000000000000000000l); test(0xffffffffffffffffl, 0b1111111111111111111111111111111111111111111111111111111111111111l); if (errors > 0) throw new Exception(errors + " errors found"); } void test(int expect, int found) { count++; if (found != expect) error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n found: 0x" + Integer.toHexString(found)); } void test(long expect, long found) { count++; if (found != expect) error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n found: 0x" + Long.toHexString(found)); } void error(String message) { System.out.println(message); errors++; } int count; int errors; }
5,156
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadBinaryLiterals.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/literals/BadBinaryLiterals.java
/* * @test /nodynamiccopyright/ * @bug 6860965 * @summary Project Coin: binary literals * @compile/fail/ref=BadBinaryLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadBinaryLiterals.java * @compile/fail/ref=BadBinaryLiterals.7.out -XDrawDiagnostics BadBinaryLiterals.java */ public class BadBinaryLiterals { int valid = 0b0; // valid literal, illegal in source 6 int baddigit = 0b012; // bad digit //aaaabbbbccccddddeeeeffffgggghhhh int overflow1 = 0b111111111111111111111111111111111; // too long for int //aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp int overflow2 = 0b11111111111111111111111111111111111111111111111111111111111111111L; // too long for long float badfloat1 = 0b01.01; // no binary floats float badfloat2 = 0b01e01; // no binary floats }
878
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
UnderscoreLiterals.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/literals/UnderscoreLiterals.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6860973 * @summary Project Coin: Underscores in literals */ public class UnderscoreLiterals { public static void main(String... args) throws Exception { new UnderscoreLiterals().run(); } public void run() throws Exception { // decimal test(1, 1); test(10, 10); test(1_0, 10); test(1__0, 10); test(1_0_0, 100); test(1__0__0, 100); test(123_456_789, 123456789); // long test(1l, 1l); test(10l, 10l); test(1_0l, 10l); test(1__0l, 10l); test(1_0_0l, 100l); test(1__0__0l, 100l); test(123_456_789l, 123456789l); // float test(.1f, .1f); test(.10f, .10f); test(.1_0f, .10f); test(.1__0f, .10f); test(.1_0_0f, .100f); test(.1__0__0f, .100f); test(1e1, 1e1); test(1e10, 1e10); test(1e1_0, 1e10); test(1e1__0, 1e10); test(1e1_0_0, 1e100); test(1e1__0__0, 1e100); test(.123_456_789f, .123456789f); test(0.1f, 0.1f); test(0.10f, 0.10f); test(0.1_0f, 0.10f); test(0.1__0f, 0.10f); test(0.1_0_0f, 0.100f); test(0.1__0__0f, 0.100f); test(0.123_456_789f, 0.123456789f); test(1_1.1f, 1_1.1f); test(1_1.10f, 1_1.10f); test(1_1.1_0f, 1_1.10f); test(1_1.1__0f, 1_1.10f); test(1_1.1_0_0f, 1_1.100f); test(1_1.1__0__0f, 1_1.100f); test(1_1.123_456_789f, 1_1.123456789f); // double test(.1d, .1d); test(.10d, .10d); test(.1_0d, .10d); test(.1__0d, .10d); test(.1_0_0d, .100d); test(.1__0__0d, .100d); test(1e1, 1e1); test(1e10, 1e10); test(1e1_0, 1e10); test(1e1__0, 1e10); test(1e1_0_0, 1e100); test(1e1__0__0, 1e100); test(.123_456_789d, .123456789d); test(0.1d, 0.1d); test(0.10d, 0.10d); test(0.1_0d, 0.10d); test(0.1__0d, 0.10d); test(0.1_0_0d, 0.100d); test(0.1__0__0d, 0.100d); test(0.123_456_789d, 0.123456789d); test(1_1.1d, 1_1.1d); test(1_1.10d, 1_1.10d); test(1_1.1_0d, 1_1.10d); test(1_1.1__0d, 1_1.10d); test(1_1.1_0_0d, 1_1.100d); test(1_1.1__0__0d, 1_1.100d); test(1_1.123_456_789d, 1_1.123456789d); // binary test(0b1, 1); test(0b10, 2); test(0b1_0, 2); test(0b1__0, 2); test(0b1_0_0, 4); test(0b1__0__0, 4); test(0b0001_0010_0011, 0x123); // octal test(01, 1); test(010, 8); test(01_0, 8); test(01__0, 8); test(01_0_0, 64); test(01__0__0, 64); test(0_1, 1); test(0_10, 8); test(0_1_0, 8); test(0_1__0, 8); test(0_1_0_0, 64); test(0_1__0__0, 64); test(0_001_002_003, 01002003); // hexadecimal test(0x1, 1); test(0x10, 16); test(0x1_0, 16); test(0x1__0, 16); test(0x1_0_0, 256); test(0x1__0__0, 256); test(0x01_02_03_04, 0x1020304); // misc long creditCardNumber = 1234_5678_9012_3456L; test(creditCardNumber, 1234567890123456L); long socialSecurityNumbers = 999_99_9999L; test(socialSecurityNumbers, 999999999L); double monetaryAmount = 12_345_132.12d; test(monetaryAmount, 12345132.12d); long hexBytes = 0xFF_EC_DE_5E; test(hexBytes, 0xffecde5e); long hexWords = 0xFFEC_DE5E; test(hexWords, 0xffecde5e); long maxLong = 0x7fff_ffff_ffff_ffffL; test(maxLong, 0x7fffffffffffffffL); long maxLongDecimal = 9223372036854775807L; long alsoMaxLong = 9_223_372_036_854_775_807L; test(alsoMaxLong, maxLongDecimal); double whyWouldYouEverDoThis = 0x1.ffff_ffff_ffff_fp10_23; double whyWouldYouEverDoEvenThis = 0x1.fffffffffffffp1023; test(whyWouldYouEverDoThis, whyWouldYouEverDoEvenThis); if (errors > 0) throw new Exception(errors + " errors found"); } void test(int value, int expect) { count++; if (value != expect) error("test " + count + "\nexpected: 0x" + Integer.toHexString(expect) + "\n found: 0x" + Integer.toHexString(value)); } void test(double value, double expect) { count++; if (value != expect) error("test " + count + "\nexpected: 0x" + expect + "\n found: 0x" + value); } void test(long value, long expect) { count++; if (value != expect) error("test " + count + "\nexpected: 0x" + Long.toHexString(expect) + "\n found: 0x" + Long.toHexString(value)); } void error(String message) { System.out.println(message); errors++; } int count; int errors; }
6,002
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6891079.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/literals/T6891079.java
/* @test /nodynamiccopyright/ * @bug 6891079 * @summary Compiler allows invalid binary literals 0b and oBL * @compile/fail/ref=T6891079.out -XDrawDiagnostics T6891079.java */ class Test { int bi = 0B; long bl = 0BL; int xi = 0X; long xl = 0XL; }
267
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6521805b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/T6521805b.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6521805 * @summary Regression: JDK5/JDK6 javac allows write access to outer class reference * @author mcimadamore * * @compile T6521805b.java */ class T6521805b { static class Outer { String this$0 = null; } public class Inner extends Outer { public void foo() { this$0 = "Hello!"; } } }
1,420
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6521805e.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/T6521805e.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6521805 * @summary Regression: JDK5/JDK6 javac allows write access to outer class reference * @author mcimadamore * * @compile/fail/ref=T6521805e.out p/Outer.java p/Sub.java -XDrawDiagnostics * @compile/fail/ref=T6521805e.out p/Sub.java p/Outer.java -XDrawDiagnostics */
1,349
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6521805a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/T6521805a.java
/* * @test /nodynamiccopyright/ * @bug 6521805 * @summary Regression: JDK5/JDK6 javac allows write access to outer class reference * @author mcimadamore * * @compile/fail/ref=T6521805a_1.out T6521805a.java -XDrawDiagnostics * @compile/ref=T6521805a_2.out T6521805a.java -XDwarnOnSyntheticConflicts -XDrawDiagnostics */ class T6521805a { static class Outer { T6521805a this$0 = null; } public class Inner extends Outer { public void foo() { this$0 = new T6521805a(); } } }
535
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6521805c.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/T6521805c.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6521805 * @summary Regression: JDK5/JDK6 javac allows write access to outer class reference * @author mcimadamore * * @compile T6521805c.java */ class T6521805c { static class Outer { T6521805c this$0() { return null;} } public class Inner extends Outer { public void foo() { this$0(); } } }
1,425
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6521805d.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/T6521805d.java
/* * @test /nodynamiccopyright/ * @bug 6521805 * @summary Regression: JDK5/JDK6 javac allows write access to outer class reference * @author mcimadamore * * @compile/fail/ref=T6521805d.out T6521805d.java -XDrawDiagnostics */ class T6521805 { static class Inner extends T6521805.Outer { Inner(T6521805 t) { t.super(); } T6521805 this$0 = null; public void foo() { this$0 = new T6521805(); } } class Outer {} }
499
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Sub.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6521805/p/Sub.java
package p; class Inner extends Outer.Super { Inner(Outer t) { t.super(); } Outer this$0 = null; public void foo() { this$0 = new Outer(); } }
181
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CyclicScoping_2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/CyclicScoping/CyclicScoping_2.java
/* * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4254215 * @summary Verify rejection of illegal cyclically-scoped class. * @author maddox * * @run compile/fail CyclicScoping_2.java */ class B { interface K {} } class A extends B implements A.I { interface I extends K { class J {} } J j; }
1,346
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CyclicScoping_1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/CyclicScoping/CyclicScoping_1.java
/* * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4257805 * @summary Verify detection of cyclically-scoped interface. * @author maddox * * @run compile/fail CyclicScoping_1.java */ interface A extends A.B { interface B {} }
1,257
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CheckClassFileVersion.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/versions/CheckClassFileVersion.java
/* * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.io.*; import java.nio.*; import java.nio.channels.*; public class CheckClassFileVersion { static String get(String fn) throws IOException { ByteBuffer bb = ByteBuffer.allocate(1024); FileChannel fc = new FileInputStream(fn).getChannel(); try { bb.clear(); if (fc.read(bb) < 0) throw new IOException("Could not read any bytes"); bb.flip(); int minor = bb.getShort(4); int major = bb.getShort(6); return major + "." + minor; } finally { fc.close(); } } public static void main(String[] args) throws IOException { String cfv = get(args[0]); if (args.length == 1) { System.out.println(cfv); return; } if (!cfv.equals(args[1])) { System.err.println("Class-file version mismatch: Expected " + args[1] + ", got " + cfv); System.exit(1); } } }
2,080
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ForwardReference_2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/ForwardReference_2.java
/* * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4312145 4307810 * @summary Verify that forward referenced static use is rejected. * @author William Maddox (maddox) * * @run compile/fail ForwardReference_2.java */ class ForwardReference_2 { static { System.out.println(x); //illegal forward reference } static int x = 1; }
1,366
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
UseBeforeDeclaration.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/UseBeforeDeclaration.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4459133 * @summary Forward reference legal or illegal? * @author gafter * * @compile UseBeforeDeclaration.java */ class UseBeforeDeclaration { static { x = 100; // ok - assignment // int y = ((x)) + 1; // error - read before declaration int v = ((x)) = 3; // ok - x at left hand side of assignment int z = UseBeforeDeclaration.x * 2; // ok - not accessed via simple name Object o = new Object(){ void foo(){x++;} // ok - occurs in a different class {x++;} // ok - occurs in a different class }; } { j = 200; // ok - assignment // j = j + 1; // error - right hand side reads before declaration // int k = j = j + 1; // error - right hand side reads before declaration int n = j = 300; // ok - j at left hand side of assignment // int h = j++; // error - read before declaration int l = this.j * 3; // ok - not accessed via simple name Object o = new Object(){ void foo(){j++;} // ok - occurs in a different class { j = j + 1;} // ok - occurs in a different class }; } int w = x= 3; // ok - x at left hand side of assignment int p = x; // ok - instance initializers may access static fields static int u = (new Object(){int bar(){return x;}}).bar(); // ok - occurs in a different class static int x; int m = j = 4; // ok - j at left hand side of assignment int o = (new Object(){int bar(){return j;}}).bar(); // ok - occurs in a different class int j; }
2,646
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6676362a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/T6676362a.java
/* * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6676362 * @summary Spurious forward reference error with final var + instance variable initializer * @author Maurizio Cimadamore * * @compile T6676362a.java */ public class T6676362a { Object o = new Object() {Object m() {return o2;}}; final Object o2 = o; }
1,345
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ForwardReference_5.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/ForwardReference_5.java
/* * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4312127 * @summary Verify that forward reference checks are not applied to locals. * @author William Maddox (maddox) * * @run compile ForwardReference_5.java */ class ForwardReference_5 { void test() { int i = (i = 1) + i++; //legal (i in scope and definitely assigned) } }
1,364
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ForwardReference_4.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/ForwardReference_4.java
/* * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4312145 4307810 * @summary Verify that forward referenced non-static use is rejected. * @author William Maddox (maddox) * * @run compile/fail ForwardReference_4.java */ class ForwardReference_4 { { System.out.println(x); //illegal forward reference } int x = 1; }
1,356
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6676362b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ForwardReference/T6676362b.java
/* * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6676362 * @summary Spurious forward reference error with final var + instance variable initializer * @author Maurizio Cimadamore * * @compile T6676362b.java */ public class T6676362b { static final int i1 = T6676362b.i2; //legal - usage is not via simple name static final int i2 = i1; }
1,374
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Test.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/FloatingPointChanges/Test.java
/* * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4150966 4151040 4107254 4180437 * @summary General tests of strictfp changes and reflection * @author David Stoutamire (dps) * * @compile Test.java * @run main Test */ import java.lang.reflect.*; public class Test { strictfp void strict() {} strictfp class Inner2 { void strict() {} } public static void main(String[] args) throws NoSuchMethodException { assertStrict(Test.class.getDeclaredMethod("strict", new Class[0])); assertStrict(Test.Inner2.class.getDeclaredMethod("strict", new Class[0])); assertStrict(Test2.class.getDeclaredMethod("strict", new Class[0])); assertStrict(Test2.class.getDeclaredMethod("strict2", new Class[0])); assertStrict(Test2.Inner.class.getDeclaredMethod("strict", new Class[0])); assertStrict(Test2.Inner2.class.getDeclaredMethod("strict", new Class[0])); } private static void assertStrict(Method m) { int mod = m.getModifiers(); if (!Modifier.isStrict(mod)) barf(m, "strict"); } private static void barf(Method m, String msg) { System.err.println("Method "+m+" was not "+msg+": " +Modifier.toString(m.getModifiers())); } } strictfp class Test2 { void strict() {} strictfp void strict2() {} class Inner { void strict() {} } strictfp class Inner2 { void strict() {} } } // check local inner classes are accepted class OtherTest { static double m() { strictfp class Inn { float i; } return 2.0; } }
2,627
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadConstructorModifiers.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/FloatingPointChanges/BadConstructorModifiers.java
/* * @test /nodynamiccopyright/ * @bug 4153038 4785453 * @summary strictfp may not be used with constructors * @author David Stoutamire (dps) * * @compile/fail/ref=BadConstructorModifiers.out -XDrawDiagnostics BadConstructorModifiers.java */ public class BadConstructorModifiers { strictfp BadConstructorModifiers (double abra) { } }
349
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T4717181a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/T4717181a.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4717181 * @summary javac treats inherited abstract method as an overrider * @author gafter * * @compile T4717181a.java */ class T4717181a { abstract class C { abstract void m(); } interface I { void m(); } abstract class D extends C implements I {} }
1,365
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
U2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/U2.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package p1; public abstract class U2 extends U1 { void f() {} }
1,121
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/T1.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4706866 * @summary javac doesn't implement transitive rule for overriding * @author gafter * * @compile T1.java T2.java T3.java */ package p1; public abstract class T1 { abstract void f(); }
1,274
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/T3.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package p3; class T3 extends p1.T2 { public void f() {} }
1,115
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
U3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/U3.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ public class U3 extends p1.U2 { }
1,086
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T4717181b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/T4717181b.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4717181 * @summary javac treats inherited abstract method as an overrider * @author gafter * * @compile T4717181b.java */ class T4717181b { static class E1 extends Exception {} static class E2 extends Exception {} static class E3 extends Exception {} static abstract class Ta { public abstract void m() throws E1, E2; } interface Tb { void m() throws E2, E3; } static abstract class Tc extends Ta implements Tb { { try { m(); // intersect throws clauses } catch (E2 e2) { } } } }
1,678
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
U1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/U1.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4706866 * @summary javac doesn't implement transitive rule for overriding * @author gafter * * @compile U1.java U2.java U3.java */ package p1; public abstract class U1 { abstract void f(); }
1,274
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/abstract/T2.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package p1; public abstract class T2 extends T1 { protected abstract void f(); }
1,138
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Dummy.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/Dummy.java
/* * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4086139 * @summary Cyclic need during import resolution causes compiler crash * @author turnidge * * @compile foo/Middle.java * @compile foo/Middle2.java */ public class Dummy {}
1,264
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Bottom.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Bottom.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; import foo.Top; public interface Bottom { }
1,117
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Middle.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Middle.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; public interface Middle extends Bottom { }
1,115
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Middle2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Middle2.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; public interface Middle2 extends Bottom2 { }
1,117
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Top.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Top.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; public interface Top extends Middle { }
1,112
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Top2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Top2.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; public interface Top2 extends Middle2 { }
1,114
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Bottom2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportCycle/foo/Bottom2.java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package foo; import foo.Top2.*; public interface Bottom2 { }
1,121
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6341866.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6341866/T6341866.java
/* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6341866 * @summary Source files loaded from source path are not subject to annotation processing * @build Anno T6341866 * @run main T6341866 */ import java.io.*; import java.util.*; import javax.annotation.processing.*; import javax.tools.*; /** * For each of a number of implicit compilation scenarios, * and for each of a set of annotation processing scenarios, * verify that a class file is generated, or not, for an * implicitly compiled source file and that the correct * warning message is given for implicitly compiled files * when annotation processing. */ public class T6341866 { static final String testSrc = System.getProperty("test.src", "."); static final String testClasses = System.getProperty("test.classes", "."); static final File a_java = new File(testSrc, "A.java"); static final File a_class = new File("A.class"); static final File b_java = new File(testSrc, "B.java"); static final File b_class = new File("B.class"); static final File processorServices = services(Processor.class); enum ImplicitType { NONE(null), // don't use implicit compilation OPT_UNSET(null), // implicit compilation, but no -implicit option OPT_NONE("-implicit:none"), // implicit compilation wiith -implicit:none OPT_CLASS("-implicit:class"); // implicit compilation wiith -implicit:class ImplicitType(String opt) { this.opt = opt; } final String opt; }; enum AnnoType { NONE, // no annotation processing SERVICE, // implicit annotation processing, via ServiceLoader SPECIFY // explicit annotation processing }; public static void main(String ... args) throws Exception { boolean ok = true; // iterate over all combinations for (ImplicitType implicitType: EnumSet.allOf(ImplicitType.class)) { for (AnnoType annoType: EnumSet.allOf(AnnoType.class)) { ok &= test(implicitType, annoType); } } if (!ok) throw new AssertionError("test failed"); } /** * Verify that a class file is generated, or not, for an implicitly compiled source file, * and that the correct warning message is given for implicitly compiled files when annotation processing. */ static boolean test(ImplicitType implicitType, AnnoType annoType) throws IOException { System.err.println("test implicit=" + implicitType + " anno=" + annoType); // ensure clean start a_class.delete(); b_class.delete(); processorServices.delete(); List<String> opts = new ArrayList<String>(); opts.addAll(Arrays.asList("-d", ".", "-sourcepath", testSrc, "-classpath", testClasses, "-source", "1.6", "-Xlint:-options")); if (implicitType.opt != null) opts.add(implicitType.opt); switch (annoType) { case SERVICE: createProcessorServices(Anno.class.getName()); break; case SPECIFY: opts.addAll(Arrays.asList("-processor", Anno.class.getName())); break; } JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); MyDiagListener dl = new MyDiagListener(); StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null); // Note: class A references class B, so compile A if we want implicit compilation File file = (implicitType != ImplicitType.NONE) ? a_java : b_java; Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); //System.err.println("compile: " + opts + " " + files); boolean ok = javac.getTask(null, fm, dl, opts, null, files).call(); if (!ok) { error("compilation failed"); return false; } // check implicit compilation results if necessary if (implicitType != ImplicitType.NONE) { boolean expectClass = (implicitType != ImplicitType.OPT_NONE); if (b_class.exists() != expectClass) { if (b_class.exists()) error("B implicitly compiled unexpectedly"); else error("B not impliictly compiled"); return false; } } // check message key results String expectKey = null; if (implicitType == ImplicitType.OPT_UNSET) { switch (annoType) { case SERVICE: expectKey = "compiler.warn.proc.use.proc.or.implicit"; break; case SPECIFY: expectKey = "compiler.warn.proc.use.implicit"; break; } } if (expectKey == null) { if (dl.diagCodes.size() != 0) { error("no diagnostics expected"); return false; } } else { if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) { error("unexpected diagnostics generated"); return false; } } return true; } static void createProcessorServices(String name) throws IOException { processorServices.getParentFile().mkdirs(); BufferedWriter out = new BufferedWriter(new FileWriter(processorServices)); out.write(name); out.newLine(); out.close(); } static class MyDiagListener implements DiagnosticListener<JavaFileObject> { public void report(Diagnostic d) { diagCodes.add(d.getCode()); System.err.println(d); } List<String> diagCodes = new ArrayList<String>(); } static void error(String msg) { System.err.println("ERROR: " + msg); } static File services(Class<?> service) { String[] dirs = { testClasses, "META-INF", "services" }; File dir = null; for (String d: dirs) dir = (dir == null ? new File(d) : new File(dir, d)); return new File(dir, service.getName()); } }
7,206
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Anno.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6341866/Anno.java
/* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.util.*; import javax.annotation.processing.*; import javax.lang.model.*; import javax.lang.model.element.*; @SupportedAnnotationTypes("*") public class Anno extends AbstractProcessor { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { //if (!roundEnv.processingOver()) // System.err.println("annotation processing"); return true; } @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } }
1,633
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6341866/A.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ class A { B b; }
1,073
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
B.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6341866/B.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ class B { }
1,064
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
package-info.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/T6232928/package-info.java
/* * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ @Deprecated package T6232928;
1,082
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6956462.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/T6956462/T6956462.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6956462 * @summary AssertionError exception throws in the Compiler Tree API in JDK 7. * * @build TestClass T6956462 * @run main T6956462 */ import java.io.*; import java.net.URISyntaxException; import java.util.*; import javax.tools.*; import javax.tools.JavaCompiler.CompilationTask; import com.sun.source.tree.*; import com.sun.source.util.*; public class T6956462 { public static void main(String[] args) throws Exception { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { throw new RuntimeException("can't get javax.tools.JavaCompiler!"); } StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); List<File> files = new ArrayList<File>(); files.add(new File(T6956462.class.getResource("TestClass.java").toURI())); final CompilationTask task = compiler.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(files)); JavacTask javacTask = (JavacTask) task; for (CompilationUnitTree cu : javacTask.parse()) { cu.accept(new MyVisitor(javacTask), null); } } private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> { private final Trees trees; private CompilationUnitTree file; private MyVisitor(JavacTask javac) { this.trees = Trees.instance(javac); } @Override public Tree visitCompilationUnit(CompilationUnitTree file, Void v) { this.file = file; for (Tree typeDecl : file.getTypeDecls()) { typeDecl.accept(this, v); } return null; } @Override public Tree visitImport(ImportTree imp, Void v) { return null; } @Override public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) { invoke.getMethodSelect().accept(this, v); return null; } @Override public Tree visitBlock(BlockTree block, Void v) { for (StatementTree stat : block.getStatements()) { stat.accept(this, v); } return null; } @Override public Tree visitClass(ClassTree clazz, Void v) { for (Tree member : clazz.getMembers()) { member.accept(this, v); } return null; } @Override public Tree visitIdentifier(IdentifierTree ident, Void v) { trees.getScope(trees.getPath(file, ident)); return null; } @Override public Tree visitMethod(MethodTree method, Void v) { method.getBody().accept(this, v); return null; } @Override public Tree visitMemberSelect(MemberSelectTree select, Void v) { select.getExpression().accept(this, v); return null; } @Override public Tree visitVariable(VariableTree var, Void v) { var.getInitializer().accept(this, v); return null; } } }
4,203
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TestClass.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/T6956462/TestClass.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.io.PrintStream; abstract class TestClass { private void test() { final PrintStream out = System.out; } }
1,186
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6491592.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6491592/T6491592.java
/* * @test /nodynamiccopyright/ * @bug 6491592 * @summary Compiler crashes on assignment operator * @author alex.buckley@... * @compile/fail/ref=T6491592.out -XDrawDiagnostics T6491592.java */ public class T6491592 { public static void main(String... args) { Object o = null; o += null; } }
327
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
MissingSuperRecovery.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/missingSuperRecovery/MissingSuperRecovery.java
/* * @test /nodynamiccopyright/ * @bug 4332631 4785453 * @summary Check for proper error recovery when superclass of extended * class is no longer available during a subsequent compilation. * @author maddox * * @compile/fail/ref=MissingSuperRecovery.out -XDdiags=%b:%l:%_%m MissingSuperRecovery.java */ // Requires "golden" class file 'impl.class', which contains // a reference to a superclass at a location no longer on the classpath. // Note that this test should elicit an error, but should not cause a compiler crash. public class MissingSuperRecovery extends impl { private String workdir=""; }
614
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6734819c.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6734819/T6734819c.java
/* * @test /nodynamiccopyright/ * @bug 6734819 * @summary Javac performs flows analysis on already translated classes * @author Maurizio Cimadamore * * @compile/fail/ref=T6734819c.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819c.java */ class Y extends W {} class W extends Z {} class Z { void m(Z z) { return; W w = (W)z; } }
377
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6734819b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6734819/T6734819b.java
/* * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6734819 * @summary Javac performs flows analysis on already translated classes * @author Maurizio Cimadamore * * @compile/ref=T6734819b.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819b.java */ class A extends B {} class B { class C extends B {} }
1,346
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6734819a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6734819/T6734819a.java
/* * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6734819 * @summary Javac performs flows analysis on already translated classes * @author Maurizio Cimadamore * * @compile/ref=T6734819a.out -XDrawDiagnostics -Xlint:all -XDverboseCompilePolicy T6734819a.java */ class Y extends W {} class W extends Z {} class Z { void m(Z z) { W w = (W)z; } }
1,387
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6889255.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6889255/T6889255.java
/* * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6889255 * @summary ClassReader does not read parameter names correctly */ import java.io.*; import java.util.*; import javax.tools.StandardLocation; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Scope; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.TypeTags; import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.jvm.ClassReader; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Names; public class T6889255 { boolean testInterfaces = true; boolean testSyntheticMethods = true; // The following enums control the generation of the test methods to be compiled. enum GenericKind { NOT_GENERIC, GENERIC }; enum ClassKind { CLASS("Clss"), INTERFACE("Intf"), ENUM("Enum"); final String base; ClassKind(String base) { this.base = base; } }; enum NestedKind { /** Declare methods inside the outermost container. */ NONE, /** Declare methods inside a container with a 'static' modifier. */ NESTED, /** Declare methods inside a container without a 'static' modifier. */ INNER, /** Declare methods inside a local class in an initializer. */ INIT_LOCAL, /** Declare methods inside an anonymous class in an initializer. */ INIT_ANON, /** Declare methods inside a local class in a method. */ METHOD_LOCAL, /** Declare methods inside an anonymous class in a method. */ METHOD_ANON }; enum MethodKind { ABSTRACT, CONSTRUCTOR, METHOD, STATIC_METHOD, BRIDGE_METHOD }; enum FinalKind { /** Method body does not reference external final variables. */ NO_FINAL, /** Method body references external final variables. */ USE_FINAL }; public static void main(String... args) throws Exception { new T6889255().run(); } void run() throws Exception { genTest(); test("no-args", false); test("g", true, "-g"); if (errors > 0) throw new Exception(errors + " errors found"); } /** * Create a file containing lots of method definitions to be tested. * There are 3 sets of nested loops that generate the methods. * 1. The outermost set declares [generic] (class | interface | enum) * 2. The middle set declares [(nested | inner | anon | local)] class * 3. The innermost set declares * [generic] (constructor|method|static-method|bridge-method) [using final variables in outer scope] * Invalid combinations are filtered out. */ void genTest() throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter("Test.java")); // This interface is used to force bridge methods to be generated, by // implementing its methods with subtypes of Object out.write("interface Base {\n"); out.write(" Object base_m1(int i1);\n"); out.write(" Object base_m2(int i1);\n"); out.write("}\n"); int outerNum = 0; // Outermost set of loops, to generate a top level container for (GenericKind outerGenericKind: GenericKind.values()) { for (ClassKind outerClassKind: ClassKind.values()) { if (outerGenericKind == GenericKind.GENERIC && outerClassKind == ClassKind.ENUM) continue; String outerClassName = outerClassKind.base + (outerNum++); String outerTypeArg = outerClassKind.toString().charAt(0) + "T"; if (outerClassKind == ClassKind.CLASS) out.write("abstract "); out.write(outerClassKind.toString().toLowerCase() + " " + outerClassName); if (outerGenericKind == GenericKind.GENERIC) out.write("<" + outerTypeArg + ">"); if (outerClassKind == ClassKind.INTERFACE) out.write(" extends Base"); else out.write(" implements Base"); out.write(" {\n"); if (outerClassKind == ClassKind.ENUM) { out.write(" E1(0,0,0), E2(0,0,0), E3(0,0,0);\n"); out.write(" " + outerClassName + "(int i1, int i2, int i3) { }\n"); } // Middle set of loops, to generate an optional nested container int nestedNum = 0; int methodNum = 0; for (GenericKind nestedGenericKind: GenericKind.values()) { nextNestedKind: for (NestedKind nestedKind: NestedKind.values()) { // if the nested kind is none, there is no point iterating over all // nested generic kinds, so arbitarily limit it to just one kind if (nestedKind == NestedKind.NONE && nestedGenericKind != GenericKind.NOT_GENERIC) continue; if ((nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.INIT_ANON) && nestedGenericKind == GenericKind.GENERIC) continue; String indent = " "; boolean haveFinal = false; switch (nestedKind) { case METHOD_ANON: case METHOD_LOCAL: if (outerClassKind == ClassKind.INTERFACE) continue nextNestedKind; out.write(indent + "void m" + + (nestedNum++) + "() {\n"); indent += " "; out.write(indent + "final int fi1 = 0;\n"); haveFinal = true; break; case INIT_ANON: case INIT_LOCAL: if (outerClassKind == ClassKind.INTERFACE) continue nextNestedKind; out.write(indent + "{\n"); indent += " "; break; } for (ClassKind nestedClassKind: ClassKind.values()) { if ((nestedGenericKind == GenericKind.GENERIC) && (nestedClassKind == ClassKind.ENUM)) continue; if ((nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.METHOD_LOCAL || nestedKind == NestedKind.INIT_ANON || nestedKind == NestedKind.INIT_LOCAL) && nestedClassKind != ClassKind.CLASS) continue; // if the nested kind is none, there is no point iterating over all // nested class kinds, so arbitarily limit it to just one kind if (nestedKind == NestedKind.NONE && nestedClassKind != ClassKind.CLASS) continue; ClassKind methodClassKind; String methodClassName; boolean allowAbstractMethods; boolean allowStaticMethods; switch (nestedKind) { case NONE: methodClassKind = outerClassKind; methodClassName = outerClassName; allowAbstractMethods = (outerClassKind == ClassKind.CLASS); allowStaticMethods = (outerClassKind != ClassKind.INTERFACE); break; case METHOD_ANON: case INIT_ANON: out.write(indent + "new Base() {\n"); indent += " "; methodClassKind = ClassKind.CLASS; methodClassName = null; allowAbstractMethods = false; allowStaticMethods = false; break; default: { // INNER, NESTED, LOCAL String nestedClassName = "N" + nestedClassKind.base + (nestedNum++); String nestedTypeArg = nestedClassKind.toString().charAt(0) + "T"; out.write(indent); if (nestedKind == NestedKind.NESTED) out.write("static "); if (nestedClassKind == ClassKind.CLASS) out.write("abstract "); out.write(nestedClassKind.toString().toLowerCase() + " " + nestedClassName); if (nestedGenericKind == GenericKind.GENERIC) out.write("<" + nestedTypeArg + ">"); if (nestedClassKind == ClassKind.INTERFACE) out.write(" extends Base "); else out.write(" implements Base "); out.write(" {\n"); indent += " "; if (nestedClassKind == ClassKind.ENUM) { out.write(indent + "E1(0,0,0), E2(0,0,0), E3(0,0,0);\n"); out.write(indent + nestedClassName + "(int i1, int i2, int i3) { }\n"); } methodClassKind = nestedClassKind; methodClassName = nestedClassName; allowAbstractMethods = (nestedClassKind == ClassKind.CLASS); allowStaticMethods = (nestedKind == NestedKind.NESTED && nestedClassKind != ClassKind.INTERFACE); break; } } // Innermost loops, to generate methods for (GenericKind methodGenericKind: GenericKind.values()) { for (FinalKind finalKind: FinalKind.values()) { for (MethodKind methodKind: MethodKind.values()) { // out.write("// " + outerGenericKind // + " " + outerClassKind // + " " + nestedKind // + " " + nestedGenericKind // + " " + nestedClassKind // + " " + methodGenericKind // + " " + finalKind // + " " + methodKind // + "\n"); switch (methodKind) { case CONSTRUCTOR: if (nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.INIT_ANON) break; if (methodClassKind != ClassKind.CLASS) break; if (finalKind == FinalKind.USE_FINAL && !haveFinal) break; out.write(indent); if (methodGenericKind == GenericKind.GENERIC) { out.write("<CT> " + methodClassName + "(CT c1, CT c2"); } else { out.write(methodClassName + "(boolean b1, char c2"); } if (finalKind == FinalKind.USE_FINAL) { // add a dummy parameter to avoid duplicate declaration out.write(", int i3) { int i = fi1; }\n"); } else out.write(") { }\n"); break; case ABSTRACT: if (!allowAbstractMethods) continue; // fallthrough case METHOD: if (finalKind == FinalKind.USE_FINAL && !haveFinal) break; out.write(indent); if (methodKind == MethodKind.ABSTRACT) out.write("abstract "); if (methodGenericKind == GenericKind.GENERIC) out.write("<MT> "); out.write("void m" + (methodNum++) + "(int i1, long l2, float f3)"); if (methodKind == MethodKind.ABSTRACT || methodClassKind == ClassKind.INTERFACE) out.write(";\n"); else { out.write(" {"); if (finalKind == FinalKind.USE_FINAL) out.write(" int i = fi1;"); out.write(" }\n"); } break; case BRIDGE_METHOD: if (methodGenericKind == GenericKind.GENERIC) break; out.write(indent); // methods Base.base_m1 and Base.base_m2 are declared for the // benefit of bridge methods. They need to be implemented // whether or not a final variable is used. String methodName = (finalKind == FinalKind.NO_FINAL ? "base_m1" : "base_m2"); out.write("public String " + methodName + "(int i1)"); if (methodClassKind == ClassKind.INTERFACE) out.write(";\n"); else { out.write(" {"); if (finalKind == FinalKind.USE_FINAL && haveFinal) out.write(" int i = fi1;"); out.write(" return null; }\n"); } break; case STATIC_METHOD: if (!allowStaticMethods) break; if (finalKind == FinalKind.USE_FINAL && !haveFinal) break; out.write(indent + "static "); if (methodGenericKind == GenericKind.GENERIC) out.write("<MT> "); out.write("void m" + (methodNum++) + "(int i1, long l2, float f3) {"); if (finalKind == FinalKind.USE_FINAL) out.write(" int i = fi1;"); out.write(" }\n"); break; } } } } if (nestedKind != NestedKind.NONE) { indent = indent.substring(0, indent.length() - 4); out.write(indent + "};\n"); } } switch (nestedKind) { case METHOD_ANON: case METHOD_LOCAL: case INIT_ANON: case INIT_LOCAL: indent = indent.substring(0, indent.length() - 4); out.write(indent + "}\n\n"); } } } out.write("}\n\n"); } } out.close(); } void test(String testName, boolean expectNames, String... opts) throws Exception { System.err.println("Test " + testName + ": expectNames:" + expectNames + " javacOpts:" + Arrays.asList(opts)); File outDir = new File(testName); outDir.mkdirs(); compile(outDir, opts); Context ctx = new Context(); JavacFileManager fm = new JavacFileManager(ctx, true, null); fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir)); ClassReader cr = ClassReader.instance(ctx); cr.saveParameterNames = true; Names names = Names.instance(ctx); Set<String> classes = getTopLevelClasses(outDir); Deque<String> work = new LinkedList<String>(classes); String classname; while ((classname = work.poll()) != null) { System.err.println("Checking class " + classname); ClassSymbol sym = cr.enterClass(names.table.fromString(classname)); sym.complete(); if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces) continue; for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) { System.err.println("Checking member " + e.sym); switch (e.sym.kind) { case Kinds.TYP: { String name = e.sym.flatName().toString(); if (!classes.contains(name)) { classes.add(name); work.add(name); } break; } case Kinds.MTH: verify((MethodSymbol) e.sym, expectNames); break; } } } } void verify(MethodSymbol m, boolean expectNames) { if ((m.flags() & Flags.SYNTHETIC) != 0 && !testSyntheticMethods) return; //System.err.println("verify: " + m.params()); int i = 1; for (VarSymbol v: m.params()) { String expectName; if (expectNames) expectName = getExpectedName(v, i); else expectName = "arg" + (i - 1); checkEqual(expectName, v.name.toString()); i++; } } String getExpectedName(VarSymbol v, int i) { // special cases: // synthetic method if (((v.owner.owner.flags() & Flags.ENUM) != 0) && v.owner.name.toString().equals("valueOf")) return "name"; // interfaces don't have saved names // -- no Code attribute for the LocalVariableTable attribute if ((v.owner.owner.flags() & Flags.INTERFACE) != 0) return "arg" + (i - 1); // abstract methods don't have saved names // -- no Code attribute for the LocalVariableTable attribute if ((v.owner.flags() & Flags.ABSTRACT) != 0) return "arg" + (i - 1); // bridge methods use xN if ((v.owner.flags() & Flags.BRIDGE) != 0) return "x" + (i - 1); // The rest of this method assumes the local conventions in the test program Type t = v.type; String s; if (t.tag == TypeTags.CLASS) s = ((ClassType) t).tsym.name.toString(); else s = t.toString(); return String.valueOf(Character.toLowerCase(s.charAt(0))) + i; } void compile(File outDir, String... opts) throws Exception { //File testSrc = new File(System.getProperty("test.src"), "."); List<String> args = new ArrayList<String>(); args.add("-d"); args.add(outDir.getPath()); args.addAll(Arrays.asList(opts)); //args.add(new File(testSrc, "Test.java").getPath()); args.add("Test.java"); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); pw.close(); if (rc != 0) { System.err.println(sw.toString()); throw new Exception("compilation failed unexpectedly"); } } Set<String> getTopLevelClasses(File outDir) { Set<String> classes = new HashSet<String>(); for (String f: outDir.list()) { if (f.endsWith(".class") && !f.contains("$")) classes.add(f.replace(".class", "")); } return classes; } void checkEqual(String expect, String found) { if (!expect.equals(found)) error("mismatch: expected:" + expect + " found:" + found); } void error(String msg) { System.err.println(msg); errors++; throw new Error(); } int errors; }
24,131
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6330997/T1.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ public class T1 { }
1,072
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6330997.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6330997/T6330997.java
/* * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6330997 * @summary javac should accept class files with major version of the next release * @author Wei Tao * @clean T1 T2 * @compile -target 7 T1.java * @compile -target 7 T2.java * @run main/othervm T6330997 */ import java.nio.*; import java.io.*; import java.nio.channels.*; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.jvm.ClassReader.BadClassFile; import com.sun.tools.javac.main.JavaCompiler; import javax.tools.ToolProvider; public class T6330997 { public static void main(String... args) { increaseMajor("T1.class", 1); increaseMajor("T2.class", 2); javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null); JavaCompiler compiler = JavaCompiler.instance(task.getContext()); try { compiler.resolveIdent("T1").complete(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Failed: unexpected exception while reading class T1"); } try { compiler.resolveIdent("T2").complete(); } catch (BadClassFile e) { System.err.println("Passed: expected completion failure " + e.getClass().getName()); return; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Failed: unexpected exception while reading class T2"); } throw new RuntimeException("Failed: no error reported"); } // Increase class file cfile's major version by delta static void increaseMajor(String cfile, int delta) { try { RandomAccessFile cls = new RandomAccessFile( new File(System.getProperty("test.classes", "."), cfile), "rw"); FileChannel fc = cls.getChannel(); ByteBuffer rbuf = ByteBuffer.allocate(2); fc.read(rbuf, 6); ByteBuffer wbuf = ByteBuffer.allocate(2); wbuf.putShort(0, (short)(rbuf.getShort(0) + delta)); fc.write(wbuf, 6); fc.force(false); cls.close(); } catch (Exception e){ e.printStackTrace(); throw new RuntimeException("Failed: unexpected exception"); } } }
3,404
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6330997/T2.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ public class T2 { }
1,072
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7023703pos.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/7023703/T7023703pos.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test * @bug 7023703 * @summary Valid code doesn't compile * @compile T7023703pos.java */ class T7023703pos { void testForLoop() { final int bug; for (;"a".equals("b");) { final int item = 0; } bug = 0; //ok } void testForEachLoop(boolean cond, java.util.Collection<Integer> c) { final int bug; for (Integer i : c) { if (cond) { final int item = 0; } } bug = 0; //ok } void testWhileLoop() { final int bug; while ("a".equals("b")) { final int item = 0; } bug = 0; //ok } void testDoWhileLoop() { final int bug; do { final int item = 0; } while ("a".equals("b")); bug = 0; //ok } private static class Inner { private final int a, b, c, d, e; public Inner() { a = b = c = d = e = 0; } } }
2,033
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7023703neg.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/7023703/T7023703neg.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test * @bug 7023703 * @summary Valid code doesn't compile * @compile/fail/ref=T7023703neg.out -XDrawDiagnostics T7023703neg.java */ class T7023703neg { void testForLoop(boolean cond) { final int bug; final int bug2; for (;cond;) { final int item = 0; bug2 = 1; //error } bug = 0; //ok } void testForEachLoop(java.util.Collection<Integer> c) { final int bug; final int bug2; for (Integer i : c) { final int item = 0; bug2 = 1; //error } bug = 0; //ok } void testWhileLoop(boolean cond) { final int bug; final int bug2; while (cond) { final int item = 0; bug2 = 1; //error } bug = 0; //ok } void testDoWhileLoop(boolean cond) { final int bug; final int bug2; do { final int item = 0; bug2 = 1; //error } while (cond); bug = 0; //ok } }
2,087
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
DA.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/treeannotests/DA.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; /** * Annotation used by TestProcessor to indicate the expected type * of the declaration to which the annotation is attached. * These annotations are expected to be found in the modifiers * field on ClassDef, MethodDef and VarDef nodes. */ @Target({FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) @interface DA { String value(); }
1,486
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TA.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/treeannotests/TA.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; /** * Annotation used by TestProcessor to indicate the expected type * to which the annotation is attached. * These annotations are expected to be found in AnnotatedType nodes. */ @Target({TYPE_USE, TYPE_PARAMETER}) @interface TA { String value(); }
1,393
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TestProcessor.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/treeannotests/TestProcessor.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.io.*; import java.util.*; import javax.annotation.processing.*; import javax.lang.model.*; import javax.lang.model.element.*; import javax.lang.model.util.*; import javax.tools.*; import com.sun.source.util.*; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.List; /** * Test processor used to check test programs using the @Test, @DA, and @TA * annotations. * * The processor looks for elements annotated with @Test, and analyzes the * syntax trees for those elements. Within such trees, the processor looks * for the DA annotations on decls and TA annotations on types. * The value of these annotations should be a simple string rendition of * the tree node to which it is attached. * The expected number of annotations is given by the parameter to the * @Test annotation itself. */ @SupportedAnnotationTypes({"Test"}) public class TestProcessor extends AbstractProcessor { public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } /** Process trees for elements annotated with the @Test(n) annotation. */ public boolean process(Set<? extends TypeElement> annos, RoundEnvironment renv) { if (renv.processingOver()) return true; Elements elements = processingEnv.getElementUtils(); Trees trees = Trees.instance(processingEnv); TypeElement testAnno = elements.getTypeElement("Test"); for (Element elem: renv.getElementsAnnotatedWith(testAnno)) { System.err.println("ELEM: " + elem); int count = getValue(getAnnoMirror(elem, testAnno), Integer.class); System.err.println("count: " + count); TreePath p = trees.getPath(elem); JavaFileObject file = p.getCompilationUnit().getSourceFile(); JCTree tree = (JCTree) p.getLeaf(); System.err.println("tree: " + tree); new TestScanner(file).check(tree, count); } return true; } /** Get the AnnotationMirror on an element for a given annotation. */ AnnotationMirror getAnnoMirror(Element e, TypeElement anno) { Types types = processingEnv.getTypeUtils(); for (AnnotationMirror m: e.getAnnotationMirrors()) { if (types.isSameType(m.getAnnotationType(), anno.asType())) return m; } return null; } /** Get the value of the value element of an annotation mirror. */ <T> T getValue(AnnotationMirror m, Class<T> type) { for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> e: m.getElementValues().entrySet()) { ExecutableElement ee = e.getKey(); if (ee.getSimpleName().contentEquals("value")) { AnnotationValue av = e.getValue(); return type.cast(av.getValue()); } } return null; } /** Report an error to the annotation processing system. */ void error(String msg) { Messager messager = processingEnv.getMessager(); messager.printMessage(Diagnostic.Kind.ERROR, msg); } /** Report an error to the annotation processing system. */ void error(JavaFileObject file, JCTree tree, String msg) { // need better API for reporting tree position errors to the messager Messager messager = processingEnv.getMessager(); String text = file.getName() + ":" + getLine(file, tree) + ": " + msg; messager.printMessage(Diagnostic.Kind.ERROR, text); } /** Get the line number for the primary position for a tree. * The code is intended to be simple, although not necessarily efficient. * However, note that a file manager such as JavacFileManager is likely * to cache the results of file.getCharContent, avoiding the need to read * the bits from disk each time this method is called. */ int getLine(JavaFileObject file, JCTree tree) { try { CharSequence cs = file.getCharContent(true); int line = 1; for (int i = 0; i < tree.pos; i++) { if (cs.charAt(i) == '\n') // jtreg tests always use Unix line endings line++; } return line; } catch (IOException e) { return -1; } } /** Scan a tree, looking for @DA and @TA annotations, and verifying that such * annotations are attached to the expected tree node matching the string * parameter of the annotation. */ class TestScanner extends TreeScanner { /** Create a scanner for a given file. */ TestScanner(JavaFileObject file) { this.file = file; } /** Check the annotations in a given tree. */ void check(JCTree tree, int expectCount) { foundCount = 0; scan(tree); if (foundCount != expectCount) error(file, tree, "Wrong number of annotations found: " + foundCount + ", expected: " + expectCount); } /** Check @DA annotations on a class declaration. */ @Override public void visitClassDef(JCClassDecl tree) { super.visitClassDef(tree); check(tree.mods.annotations, "DA", tree); } /** Check @DA annotations on a method declaration. */ @Override public void visitMethodDef(JCMethodDecl tree) { super.visitMethodDef(tree); check(tree.mods.annotations, "DA", tree); } /** Check @DA annotations on a field, parameter or local variable declaration. */ @Override public void visitVarDef(JCVariableDecl tree) { super.visitVarDef(tree); check(tree.mods.annotations, "DA", tree); } /** Check @TA annotations on a type. */ public void visitAnnotatedType(JCAnnotatedType tree) { super.visitAnnotatedType(tree); check(tree.annotations, "TA", tree); } /** Check to see if a list of annotations contains a named annotation, and * if so, verify the annotation is expected by comparing the value of the * annotation's argument against the string rendition of the reference tree * node. * @param annos the list of annotations to be checked * @param name the name of the annotation to be checked * @param tree the tree against which to compare the annotations's argument */ void check(List<? extends JCAnnotation> annos, String name, JCTree tree) { for (List<? extends JCAnnotation> l = annos; l.nonEmpty(); l = l.tail) { JCAnnotation anno = l.head; if (anno.annotationType.toString().equals(name) && (anno.args.size() == 1)) { String expect = getStringValue(anno.args.head); foundCount++; System.err.println("found: " + name + " " + expect); String found = new TypePrinter().print(tree); if (!found.equals(expect)) error(file, anno, "Unexpected result: expected: \"" + expect + "\", found: \"" + found + "\""); } } } /** Get the string value of an annotation argument, which is given by the * expression <i>name</i>=<i>value</i>. */ String getStringValue(JCExpression e) { if (e.getTag() == JCTree.ASSIGN) { JCAssign a = (JCAssign) e; JCExpression rhs = a.rhs; if (rhs.getTag() == JCTree.LITERAL) { JCLiteral l = (JCLiteral) rhs; return (String) l.value; } } throw new IllegalArgumentException(e.toString()); } /** The file for the tree. Used to locate errors. */ JavaFileObject file; /** The number of annotations that have been found. @see #check */ int foundCount; } /** Convert a type or decl tree to a reference string used by the @DA and @TA annotations. */ class TypePrinter extends Visitor { /** Convert a type or decl tree to a string. */ String print(JCTree tree) { if (tree == null) return null; tree.accept(this); return result; } String print(List<? extends JCTree> list) { return print(list, ", "); } String print(List<? extends JCTree> list, String sep) { StringBuilder sb = new StringBuilder(); if (list.nonEmpty()) { sb.append(print(list.head)); for (List<? extends JCTree> l = list.tail; l.nonEmpty(); l = l.tail) { sb.append(sep); sb.append(print(l.head)); } } return sb.toString(); } @Override public void visitClassDef(JCClassDecl tree) { result = tree.name.toString(); } @Override public void visitMethodDef(JCMethodDecl tree) { result = tree.name.toString(); } @Override public void visitVarDef(JCVariableDecl tree) { tree.vartype.accept(this); } @Override public void visitAnnotatedType(JCAnnotatedType tree) { tree.underlyingType.accept(this); } @Override public void visitTypeIdent(JCPrimitiveTypeTree tree) { result = tree.toString(); } @Override public void visitTypeArray(JCArrayTypeTree tree) { result = print(tree.elemtype) + "[]"; } @Override public void visitTypeApply(JCTypeApply tree) { result = print(tree.clazz) + "<" + print(tree.arguments) + ">"; } @Override public void visitTypeParameter(JCTypeParameter tree) { if (tree.bounds.isEmpty()) result = tree.name.toString(); else result = tree.name + " extends " + print(tree.bounds, "&"); } @Override public void visitWildcard(JCWildcard tree) { if (tree.kind.kind == BoundKind.UNBOUND) result = tree.kind.toString(); else result = tree.kind + " " + print(tree.inner); } private String result; } }
11,575
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Test.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/treeannotests/Test.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * Annotation used by TestProcessor to indicate the expected number of * @DA and @TA annotations in the source tree to which the Test annotation * is attached. */ @interface Test { int value(); }
1,260
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
C.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6400872/C.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ class C { A a = new A(); B b = new B(); }
1,104
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6400872.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6400872/T6400872.java
/* * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6400872 * @summary REGRESSION: Java Compiler cannot find jar files referenced by other * @run main T6400872 */ // ${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTSRC}/A.java ${TESTSRC}/B.java // ${TESTJAVA}/bin/jar -cfm A.jar ${TESTSRC}/A/META-INF/MANIFEST.MF -C ${TESTCLASSES} A.class // ${TESTJAVA}/bin/jar -cfm B.jar ${TESTSRC}/B/META-INF/MANIFEST.MF -C ${TESTCLASSES} B.class // ${TESTJAVA}/bin/javac -cp A.jar ${TESTSRC}/C.java import java.io.*; import java.nio.*; import java.util.*; import java.util.jar.*; import javax.tools.*; import javax.tools.StandardJavaFileManager.*; public class T6400872 { static File testSrc = new File(System.getProperty("test.src", ".")); static File testClasses = new File(System.getProperty("test.classes", ".")); public static void main(String... args) throws Exception { // compile A.java and B.java compile(testClasses, null, new File(testSrc, "A.java"), new File(testSrc, "B.java")); // put them in mutually referential class files jar(new File("A.jar"), iterable(new File(".", "B.jar")), testClasses, new File("A.class")); jar(new File("B.jar"), iterable(new File(".", "A.jar")), testClasses, new File("B.class")); // verify we can successfully use the class path entries in the jar files compile(new File("."), iterable(new File("A.jar")), new File(testSrc, "C.java")); } static void compile(File classOutDir, Iterable<File> classPath, File... files) throws IOException { System.err.println("compile..."); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); try { Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjectsFromFiles(Arrays.asList(files)); List<String> options = new ArrayList<String>(); if (classOutDir != null) { options.add("-d"); options.add(classOutDir.getPath()); } if (classPath != null) { options.add("-classpath"); options.add(join(classPath, File.pathSeparator)); } options.add("-verbose"); JavaCompiler.CompilationTask task = compiler.getTask(null, fm, null, options, null, fileObjects); if (!task.call()) throw new AssertionError("compilation failed"); } finally { fm.close(); } } static void jar(File jar, Iterable<File> classPath, File base, File... files) throws IOException { System.err.println("jar..."); Manifest m = new Manifest(); if (classPath != null) { Attributes mainAttrs = m.getMainAttributes(); mainAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); mainAttrs.put(Attributes.Name.CLASS_PATH, join(classPath, " ")); } OutputStream out = new BufferedOutputStream(new FileOutputStream(jar)); JarOutputStream j = new JarOutputStream(out, m); add(j, base, files); j.close(); } static void add(JarOutputStream j, File base, File... files) throws IOException { if (files == null) return; for (File f: files) add(j, base, f); } static void add(JarOutputStream j, File base, File file) throws IOException { File f = new File(base, file.getPath()); if (f.isDirectory()) { String[] children = f.list(); if (children != null) for (String c: children) add(j, base, new File(file, c)); } else { JarEntry e = new JarEntry(file.getPath()); e.setSize(f.length()); j.putNextEntry(e); j.write(read(f)); j.closeEntry(); } } static byte[] read(File f) throws IOException { byte[] buf = new byte[(int) f.length()]; BufferedInputStream in = new BufferedInputStream(new FileInputStream(f)); int offset = 0; while (offset < buf.length) { int n = in.read(buf, offset, buf.length - offset); if (n < 0) throw new EOFException(); offset += n; } return buf; } static <T> Iterable<T> iterable(T single) { return Collections.singleton(single); } static <T> String join(Iterable<T> iter, String sep) { StringBuilder p = new StringBuilder(); for (T t: iter) { if (p.length() > 0) p.append(' '); p.append(t); } return p.toString(); } }
5,793
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6400872/A.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ class A { B b = new B(); B getB() { return b; } }
1,111
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
B.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6400872/B.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ class B { A a = new A(); A getA() { return a; } }
1,111
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T5090006.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/T5090006/T5090006.java
/* * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5090006 * @summary javac fails with assertion error * @author Peter von der Ah\u00e9 * @run shell compiler.sh T5090006.java * @run main T5090006 */ import stub_tie_gen.wsdl_hello_lit.client.*; import junit.framework.*; import testutil.ClientServerTestUtil; public class T5090006 { void getStub() throws Exception { Hello_PortType_Stub x = null; new ClientServerTestUtil().setTransport(x, null, null, null); } public static void main(String[] args) { System.out.println("FISK"); } }
1,609
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
NullAppend2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/expression/NullAppend2.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4717193 * @summary javac improperly allows null + 1 * @author gafter * * @compile/fail NullAppend2.java */ class NullAppend2 {{ String s = null + 1; }}
1,234
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
NullAppend.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/expression/NullAppend.java
/* * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4620794 * @summary compiler allows null + null * @author gafter * * @compile/fail NullAppend.java */ class NullAppend {{ String s = null + null; }}
1,230
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6597678.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/util/T6597678.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6597678 * @summary Ensure Messages propogated between rounds * @library ../lib * @build JavacTestingAbstractProcessor T6597678 * @run main T6597678 */ import java.io.*; import java.util.*; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedOptions; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JavacMessages; public class T6597678 extends JavacTestingAbstractProcessor { public static void main(String... args) throws Exception { new T6597678().run(); } void run() throws Exception { String myName = T6597678.class.getSimpleName(); File testSrc = new File(System.getProperty("test.src")); File file = new File(testSrc, myName + ".java"); compile( "-proc:only", "-processor", myName, file.getPath()); } void compile(String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); int rc = com.sun.tools.javac.Main.compile(args, pw); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (rc != 0) throw new Exception("compilation failed unexpectedly: rc=" + rc); } //--------------- @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); Locale locale = context.get(Locale.class); JavacMessages messages = context.get(JavacMessages.messagesKey); round++; if (round == 1) { initialLocale = locale; initialMessages = messages; } else { checkEqual("locale", locale, initialLocale); checkEqual("messages", messages, initialMessages); } return true; } <T> void checkEqual(String label, T actual, T expected) { if (actual != expected) messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected value for " + label + "; expected: " + expected + "; found: " + actual); } int round = 0; Locale initialLocale; JavacMessages initialMessages; }
3,551
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TList.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/util/list/TList.java
/* * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6267067 6351336 6389198 * @summary unit test for javac List */ import java.util.*; import com.sun.tools.javac.util.List; public class TList { public static void main(String[] args) { new TList().run(); } String[][] data = { { }, { "1" }, { "1", "2" }, { "1", "2" }, // different but equal { "1", "2", "3", "4", "X", "X", "X", "8", "9", "10" } // contains duplicates }; Map<java.util.List<String>,List<String>> examples; void run() { examples = new LinkedHashMap<java.util.List<String>,List<String>>(); for (String[] values: data) examples.put(Arrays.asList(values), createList(values)); // 6351336: com.sun.tools.javac.util.List shouldn't extend java.util.AbstractList test_AbstractList(); // general unit tests for java.util.List methods, including... // 6389198: com.sun.tools.javac.util.List.equals() violates java.util.List.equals() contract test_add_E(); test_add_int_E(); test_addAll_Collection(); test_addAll_int_Collection(); test_clear(); test_contains_Object(); test_contains_All(); test_equals_Object(); test_get_int(); test_hashCode(); test_indexOf_Object(); test_isEmpty(); test_iterator(); test_lastIndexOf_Object(); test_listIterator(); test_listIterator_int(); test_remove_int(); test_remove_Object(); test_removeAll_Collection(); test_retainAll_Collection(); test_set_int_E(); test_size(); test_subList_int_int(); test_toArray(); test_toArray_TArray(); // tests for additional methods test_prependList_List(); test_reverse(); } // 6351336 void test_AbstractList() { System.err.println("test AbstractList"); if (AbstractList.class.isAssignableFrom(List.class)) throw new AssertionError(); } void test_add_E() { System.err.println("test add(E)"); for (List<String> l: examples.values()) { try { l.add("test"); throw new AssertionError(); } catch (UnsupportedOperationException ex) { } } } void test_add_int_E() { System.err.println("test add(int,E)"); for (List<String> l: examples.values()) { try { l.add(0, "test"); throw new AssertionError(); } catch (UnsupportedOperationException ex) { } } } void test_addAll_Collection() { System.err.println("test addAll(Collection)"); for (List<String> l: examples.values()) { int l_size = l.size(); for (java.util.List<String> arg: examples.keySet()) { try { boolean modified = l.addAll(arg); if (modified) throw new AssertionError(); } catch (UnsupportedOperationException e) { } if (l.size() != l_size) throw new AssertionError(); } } } void test_addAll_int_Collection() { System.err.println("test addAll(int,Collection)"); for (List<String> l: examples.values()) { int l_size = l.size(); for (java.util.List<String> arg: examples.keySet()) { try { boolean modified = l.addAll(0, arg); if (modified) throw new AssertionError(); } catch (UnsupportedOperationException e) { } if (l.size() != l_size) throw new AssertionError(); } } } void test_clear() { System.err.println("test clear()"); for (List<String> l: examples.values()) { int l_size = l.size(); try { l.clear(); if (l_size > 0) throw new AssertionError(); } catch (UnsupportedOperationException e) { } if (l.size() != l_size) throw new AssertionError(); } } void test_contains_Object() { System.err.println("test contains(Object)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); boolean expect = ref.contains("1"); boolean found = l.contains("1"); if (expect != found) throw new AssertionError(); } } void test_contains_All() { System.err.println("test containsAll()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (java.util.List<String> arg: examples.keySet()) { boolean expect = ref.containsAll(arg); boolean found = l.containsAll(arg); if (expect != found) throw new AssertionError(); } } } // 6389198 void test_equals_Object() { System.err.println("test equals(Object)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (java.util.List<String> arg: examples.keySet()) { boolean expect = ref.equals(arg); boolean found = l.equals(arg); if (expect != found) { System.err.println("ref: " + ref); System.err.println("l: " + l); System.err.println("arg: " + arg); System.err.println("expect: " + expect + ", found: " + found); throw new AssertionError(); } } } } void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } } void test_hashCode() { System.err.println("test hashCode()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); long expect = ref.hashCode(); long found = l.hashCode(); if (expect != found) { System.err.println("ref: " + ref); System.err.println("l: " + l); System.err.println("expect: " + expect); System.err.println("found: " + found); throw new AssertionError(); } } } void test_indexOf_Object() { System.err.println("test indexOf(Object)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i < ref.size(); i++) { String arg = (i == -1 ? "NOT IN LIST" : ref.get(i)); int expect = ref.indexOf(arg); int found = l.indexOf(arg); if (expect != found) throw new AssertionError(); } } } void test_isEmpty() { System.err.println("test isEmpty()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); boolean expect = ref.isEmpty(); boolean found = l.isEmpty(); if (expect != found) throw new AssertionError(); } } void test_iterator() { System.err.println("test iterator()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); if (!equal(l.iterator(), ref.iterator())) throw new AssertionError(); } } void test_lastIndexOf_Object() { System.err.println("test lastIndexOf(Object)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i < ref.size(); i++) { String arg = (i == -1 ? "NOT IN LIST" : ref.get(i)); int expect = ref.lastIndexOf(arg); int found = l.lastIndexOf(arg); if (expect != found) throw new AssertionError(); } } } void test_listIterator() { System.err.println("test listIterator()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); if (!equal(l.listIterator(), ref.listIterator())) throw new AssertionError(); } } void test_listIterator_int() { System.err.println("test listIterator(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = 0; i < ref.size(); i++) { if (!equal(l.listIterator(i), ref.listIterator(i))) throw new AssertionError(); } } } void test_remove_int() { System.err.println("test remove(int)"); for (List<String> l: examples.values()) { try { l.remove(0); throw new AssertionError(); } catch (UnsupportedOperationException ex) { } } } void test_remove_Object() { System.err.println("test remove(Object)"); for (List<String> l: examples.values()) { boolean hasX = l.contains("X"); try { l.remove("X"); if (hasX) throw new AssertionError(); } catch (UnsupportedOperationException ex) { } } } void test_removeAll_Collection() { System.err.println("test removeAll(Collection)"); for (List<String> l: examples.values()) { int l_size = l.size(); for (java.util.List<String> arg: examples.keySet()) { try { boolean modified = l.removeAll(arg); if (modified) throw new AssertionError(); } catch (UnsupportedOperationException e) { } if (l.size() != l_size) throw new AssertionError(); } } } void test_retainAll_Collection() { System.err.println("test retainAll(Collection)"); for (List<String> l: examples.values()) { int l_size = l.size(); for (java.util.List<String> arg: examples.keySet()) { try { boolean modified = l.retainAll(arg); if (modified) throw new AssertionError(); } catch (UnsupportedOperationException e) { } if (l.size() != l_size) throw new AssertionError(); } } } void test_set_int_E() { System.err.println("test set(int,E)"); for (List<String> l: examples.values()) { try { l.set(0, "X"); throw new AssertionError(); } catch (UnsupportedOperationException ex) { } } } void test_size() { System.err.println("test size()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); int expect = ref.size(); int found = l.size(); if (expect != found) throw new AssertionError(); } } void test_subList_int_int() { System.err.println("test subList(int,int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int lwb = 0; lwb < ref.size(); lwb++) { for (int upb = lwb; upb <= ref.size(); upb++) { if (!equal(l.subList(lwb, upb), ref.subList(lwb,upb))) throw new AssertionError(); } } } } void test_toArray() { System.err.println("test toArray()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); if (!equal(l.toArray(), ref.toArray())) throw new AssertionError(); } } void test_toArray_TArray() { System.err.println("test toArray(E[])"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); if (!equal(l.toArray(new String[0]), ref.toArray(new String[0]))) throw new AssertionError(); } } void test_prependList_List() { System.err.println("test prependList(List<E>)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (Map.Entry<java.util.List<String>, List<String>> arg_e: examples.entrySet()) { java.util.List<String> arg_ref = arg_e.getKey(); List<String> arg = arg_e.getValue(); java.util.List<String> expect = join(arg, ref); List<String> found = l.prependList(arg); // verify results, and that original and arg lists are unchanged if (!equal(expect, found)) { System.err.println("ref: " + ref); System.err.println("l: " + l); System.err.println("arg: " + arg); System.err.println("expect: " + expect); System.err.println("found: " + found); throw new AssertionError(); } if (!equal(l, ref)) throw new AssertionError(); if (!equal(arg, arg_ref)) throw new AssertionError(); } } } void test_reverse() { System.err.println("test reverse()"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); java.util.List<String> expect = reverse(ref); List<String> found = l.reverse(); if (l.size() < 2 && found != l) // reverse of empty or singleton list is itself throw new AssertionError(); if (!equal(l, ref)) // orginal should be unchanged throw new AssertionError(); if (!equal(expect, found)) throw new AssertionError(); } } static <T> com.sun.tools.javac.util.List<T> createList(List<T> d) { com.sun.tools.javac.util.List<T> l = com.sun.tools.javac.util.List.nil(); for (ListIterator<T> iter = d.listIterator(d.size()); iter.hasPrevious(); ) l = l.prepend(iter.previous()); return l; } static <T> com.sun.tools.javac.util.List<T> createList(T... d) { com.sun.tools.javac.util.List<T> l = com.sun.tools.javac.util.List.nil(); for (int i = d.length - 1; i >= 0; i--) l = l.prepend(d[i]); return l; } static <T> boolean equal(T t1, T t2) { return (t1 == null ? t2 == null : t1.equals(t2)); } static <T> boolean equal(Iterator<T> iter1, Iterator<T> iter2) { if (iter1 == null || iter2 == null) return (iter1 == iter2); while (iter1.hasNext() && iter2.hasNext()) { if (!equal(iter1.next(), iter2.next())) return false; } return (!iter1.hasNext() && !iter2.hasNext()); } static <T> boolean equal(ListIterator<T> iter1, ListIterator<T> iter2) { if (iter1 == null || iter2 == null) return (iter1 == iter2); if (iter1.previousIndex() != iter2.previousIndex()) return false; while (iter1.hasPrevious() && iter2.hasPrevious()) { iter1.previous(); iter2.previous(); } return equal((Iterator<T>) iter1, (Iterator<T>) iter2); } static <T> boolean equal(T[] a1, T[] a2) { if (a1 == null || a2 == null) return (a1 == a2); if (a1.length != a2.length) return false; for (int i = 0; i < a1.length; i++) { if (!equal(a1[i], a2[i])) return false; } return true; } static <T> java.util.List<T> join(java.util.List<T>... lists) { java.util.List<T> r = new ArrayList<T>(); for (java.util.List<T> l: lists) r.addAll(l); return r; } static <T> java.util.List<T> reverse(java.util.List<T> l) { java.util.List<T> r = new ArrayList<T>(l.size()); for (T t: l) r.add(0, t); return r; } }
19,730
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7021650.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/util/context/T7021650.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 7021650 * @summary Fix Context issues * @library ../../lib * @build JavacTestingAbstractProcessor T7021650 * @run main T7021650 */ import java.io.*; import java.net.*; import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; import javax.tools.*; import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.main.Main; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.util.Context; public class T7021650 extends JavacTestingAbstractProcessor { public static void main(String... args) throws Exception { new T7021650().run(); } static File testSrc = new File(System.getProperty("test.src")); static final int MAX_ROUNDS = 3; /** * Perform a compilation with custom factories registered in the context, * and verify that corresponding objects are created in each round. */ void run() throws Exception { Counter demoCounter = new Counter(); Counter myAttrCounter = new Counter(); Context context = new Context(); // Use a custom file manager which creates classloaders for annotation // processors with a sensible delegation parent, so that all instances // of test classes come from the same class loader. This is important // because the test performs class checks on the instances of classes // found in the context for each round or processing. context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { public JavaFileManager make(Context c) { return new JavacFileManager(c, true, null) { @Override protected ClassLoader getClassLoader(URL[] urls) { return new URLClassLoader(urls, T7021650.class.getClassLoader()); } }; } }); Demo.preRegister(context, demoCounter); MyAttr.preRegister(context, myAttrCounter); String[] args = { "-d", ".", "-processor", T7021650.class.getName(), "-XprintRounds", new File(testSrc, T7021650.class.getName() + ".java").getPath() }; compile(context, args); // Expect to create Demo for initial round, then MAX_ROUNDS in which // GenX files are generated, then standard final round of processing. checkEqual("demoCounter", demoCounter.count, MAX_ROUNDS + 2); // Expect to create MyAttr for same processing rounds as for Demo, // plus additional context for final compilation. checkEqual("myAttrCounter", myAttrCounter.count, MAX_ROUNDS + 3); } void compile(Context context, String... args) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Main m = new Main("javac", pw); int rc = m.compile(args, context); pw.close(); String out = sw.toString(); if (!out.isEmpty()) System.err.println(out); if (rc != 0) throw new Exception("compilation failed unexpectedly: rc=" + rc); } void checkEqual(String label, int found, int expect) throws Exception { if (found != expect) throw new Exception("unexpected value for " + label + ": expected " + expect + ": found " + found); } //--------------- /* * A custom class unknown to javac but nonetheless registered in the context. */ static class Demo { static void preRegister(Context context, final Counter counter) { context.put(Demo.class, new Context.Factory<Demo>() { public Demo make(Context c) { counter.count++; return new Demo(c); } }); } Demo(Context c) { c.put(Demo.class, this); } static Demo instance(Context context) { return context.get(Demo.class); } } /** * A custom version of a standard javac component. */ static class MyAttr extends Attr { static void preRegister(Context context, final Counter counter) { context.put(attrKey, new Context.Factory<Attr>() { public Attr make(Context c) { counter.count++; return new MyAttr(c); } }); } MyAttr(Context c) { super(c); } } static class Counter { int count; } //--------------- int round = 0; @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); // verify items in context as expected check("Demo", Demo.instance(context), Demo.class); check("Attr", Attr.instance(context), MyAttr.class); // For a few rounds, generate new source files, so that we can check whether // values in the context are correctly handled in subsequent processing rounds if (round <= MAX_ROUNDS) { String pkg = "p"; String currClass = "Gen" + round; String curr = pkg + "." + currClass; String next = (pkg + ".Gen" + (round + 1)); StringBuilder text = new StringBuilder(); text.append("package ").append(pkg).append(";\n"); text.append("public class ").append(currClass).append(" {\n"); if (round < MAX_ROUNDS) text.append(" ").append(next).append(" x;\n"); text.append("}\n"); try { JavaFileObject fo = filer.createSourceFile(curr); Writer out = fo.openWriter(); try { out.write(text.toString()); } finally { out.close(); } } catch (IOException e) { throw new Error(e); } } return true; } void check(String label, Object o, Class<?> clazz) { if (o == null) throw new IllegalStateException(label + ": no item found"); if (!clazz.isAssignableFrom(o.getClass())) throw new IllegalStateException(label + ": unexpected class: " + o.getClass()); } }
7,580
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TestName.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/util/filemanager/TestName.java
/* * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6409829 * @summary JSR 199: enforce the use of valid package and class names * in get{Java,}FileFor{Input,Output} * @author Peter von der Ah\u00e9 */ import com.sun.tools.javac.file.JavacFileManager; public class TestName { public static void main(String... args) { final boolean PACKAGE = true; final boolean CLASS = true; JavacFileManager.testName("", PACKAGE, !CLASS); JavacFileManager.testName(".", !PACKAGE, !CLASS); JavacFileManager.testName("java.lang.", !PACKAGE, !CLASS); JavacFileManager.testName(".java.lang.", !PACKAGE, !CLASS); JavacFileManager.testName(".java.lang", !PACKAGE, !CLASS); JavacFileManager.testName("java.lang", PACKAGE, CLASS); JavacFileManager.testName("java.lang.Foo Bar", !PACKAGE, !CLASS); JavacFileManager.testName("java.lang.Foo+Bar", !PACKAGE, !CLASS); JavacFileManager.testName("java.lang.Foo$Bar", PACKAGE, CLASS); JavacFileManager.testName("Peter.von.der.Ah\u00e9", PACKAGE, CLASS); } }
2,136
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7013865.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/T7013865.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 7013865 * @summary varargs: javac crashes during overload resolution with generic varargs * @compile T7013865.java */ class T7013865 { public <X extends Number> void m(X... args) { } public void m(Object... args) { } { m(null, null); } }
1,331
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
VarargsOverride.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/VarargsOverride.java
/* * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4984022 * @summary overriding with method of different arity is prohibited * @author gafter * * @compile VarargsOverride.java * @compile/fail -Werror -Xlint VarargsOverride.java */ package varargs.override; class A { void f(Object[] o) {} } class B extends A { void f(Object... o) {} }
1,383
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Anon.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/Anon.java
/* * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4986231 * @summary varargs versus anonymous constructors crashes javac * @author gafter * * @compile Anon.java */ class Anon { Anon() { Fox fox1 = new Fox(1) {}; Fox fox2 = new Fox(new String[] { "hello" }) {}; Fox fox3 = new Fox(null) {}; Fox fox4 = new Fox() {}; Fox fox5 = new Fox("hello") {}; Fox fox6 = new Fox("hello", "bye") {}; } } class Fox { Fox(int a) { _keys = new String[0]; } Fox(String... keys) { _keys = keys; } final String[] _keys; }
1,627
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadSyntax2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/BadSyntax2.java
/* * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4901611 5009693 4920438 * @summary generic class method with vararg gets "java.lang.AssertionError: arraycode T" * @author gafter * * @compile BadSyntax2.java */ class Tclass<T> { T data; public Tclass(T... t){} } public class BadSyntax2 { String s = null; Tclass<String> tc = new Tclass<String>(s); //this gets Assertion public BadSyntax2() {} }
1,454
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/Warn2.java
/* * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5024518 * @summary need warning if varargs argument isn't boxed * @author gafter * * @compile Warn2.java * @compile/fail -Werror Warn2.java * @compile -Werror -Xlint:none Warn2.java */ package varargs.warn2; class T { static void f(String fmt, Object... args) {} public static void main(String[] args) { f("foo", null); } }
1,477
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/Warn1.java
/* * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5024518 * @summary need warning if varargs argument isn't boxed * @author gafter * * @compile Warn1.java * @compile/fail -Werror Warn1.java * @compile -Werror -Xlint:none Warn1.java */ package varargs.warn1; class T { static void f(String fmt, Object... args) {} public static void main(String[] args) { f("foo", args); } }
1,477
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6746184.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/T6746184.java
/* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6746184 * @summary javac fails to compile call to public varargs method */ public class T6746184 { public static void main(String[] args) { A.m(new Object()); } } class A { public static void m(final Object... varargs) {} private static void m(final Object singleArg) {} }
1,383
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Varargs1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/Varargs1.java
/* * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 4856541 4812161 * @summary varags, auto boxing * @author gafter * * @compile Varargs1.java * @run main Varargs1 */ public class Varargs1 { static int f(String s, int a, short b) { return 1; } static int f(String s, int a, int b) { return 2; } static int f(String s, Integer ... args) { return 3; } static int f(String s, Number ... args) { return 4; } static int f(String s, Object ... args) { return 5; } static int f(int ... args) { return 6; } static void check(int expected, int actual) { if (actual != expected) throw new AssertionError(actual); } public static void main(String[] args) { check(1, f("x", 12, (short)13)); check(2, f("x", 12, 13)); check(3, f("x", 12, 13, 14)); check(4, f("x", 12, 13.5)); check(5, f("x", 12, true)); check(6, f(12, 13)); } }
2,012
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn4.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/warning/Warn4.java
/* * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6945418 6993978 * @summary Project Coin: Simplified Varargs Method Invocation * @author mcimadamore * @run main Warn4 */ import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.JavacTool; import java.net.URI; import java.util.Arrays; import java.util.Set; import java.util.HashSet; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class Warn4 { final static Warning[] error = null; final static Warning[] none = new Warning[] {}; final static Warning[] vararg = new Warning[] { Warning.VARARGS }; final static Warning[] unchecked = new Warning[] { Warning.UNCHECKED }; final static Warning[] both = new Warning[] { Warning.VARARGS, Warning.UNCHECKED }; enum Warning { UNCHECKED("generic.array.creation"), VARARGS("varargs.non.reifiable.type"); String key; Warning(String key) { this.key = key; } boolean isSuppressed(TrustMe trustMe, SourceLevel source, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl, ModifierKind modKind) { switch(this) { case VARARGS: return source == SourceLevel.JDK_6 || suppressLevelDecl == SuppressLevel.UNCHECKED || trustMe == TrustMe.TRUST; case UNCHECKED: return suppressLevelClient == SuppressLevel.UNCHECKED || (trustMe == TrustMe.TRUST && modKind != ModifierKind.NONE && source == SourceLevel.JDK_7); } SuppressLevel supLev = this == VARARGS ? suppressLevelDecl : suppressLevelClient; return supLev == SuppressLevel.UNCHECKED || (trustMe == TrustMe.TRUST && modKind != ModifierKind.NONE); } } enum SourceLevel { JDK_6("6"), JDK_7("7"); String sourceKey; SourceLevel(String sourceKey) { this.sourceKey = sourceKey; } } enum TrustMe { DONT_TRUST(""), TRUST("@java.lang.SafeVarargs"); String anno; TrustMe(String anno) { this.anno = anno; } } enum ModifierKind { NONE(" "), FINAL("final "), STATIC("static "); String mod; ModifierKind(String mod) { this.mod = mod; } } enum SuppressLevel { NONE(""), UNCHECKED("unchecked"); String lint; SuppressLevel(String lint) { this.lint = lint; } String getSuppressAnno() { return "@SuppressWarnings(\"" + lint + "\")"; } } enum Signature { UNBOUND("void #name(List<?>#arity arg) { #body }", new Warning[][] {none, none, none, none, error}), INVARIANT_TVAR("<Z> void #name(List<Z>#arity arg) { #body }", new Warning[][] {both, both, error, both, error}), TVAR("<Z> void #name(Z#arity arg) { #body }", new Warning[][] {both, both, both, both, vararg}), INVARIANT("void #name(List<String>#arity arg) { #body }", new Warning[][] {error, error, error, both, error}), UNPARAMETERIZED("void #name(String#arity arg) { #body }", new Warning[][] {error, error, error, error, none}); String template; Warning[][] warnings; Signature(String template, Warning[][] warnings) { this.template = template; this.warnings = warnings; } boolean isApplicableTo(Signature other) { return warnings[other.ordinal()] != null; } boolean giveUnchecked(Signature other) { return warnings[other.ordinal()] == unchecked || warnings[other.ordinal()] == both; } boolean giveVarargs(Signature other) { return warnings[other.ordinal()] == vararg || warnings[other.ordinal()] == both; } } public static void main(String... args) throws Exception { for (SourceLevel sourceLevel : SourceLevel.values()) { for (TrustMe trustMe : TrustMe.values()) { for (SuppressLevel suppressLevelClient : SuppressLevel.values()) { for (SuppressLevel suppressLevelDecl : SuppressLevel.values()) { for (ModifierKind modKind : ModifierKind.values()) { for (Signature vararg_meth : Signature.values()) { for (Signature client_meth : Signature.values()) { if (vararg_meth.isApplicableTo(client_meth)) { test(sourceLevel, trustMe, suppressLevelClient, suppressLevelDecl, modKind, vararg_meth, client_meth); } } } } } } } } } // Create a single file manager and reuse it for each compile to save time. static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); static void test(SourceLevel sourceLevel, TrustMe trustMe, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl, ModifierKind modKind, Signature vararg_meth, Signature client_meth) throws Exception { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaSource source = new JavaSource(trustMe, suppressLevelClient, suppressLevelDecl, modKind, vararg_meth, client_meth); DiagnosticChecker dc = new DiagnosticChecker(); JavacTask ct = (JavacTask)tool.getTask(null, fm, dc, Arrays.asList("-Xlint:unchecked", "-source", sourceLevel.sourceKey), null, Arrays.asList(source)); ct.generate(); //to get mandatory notes check(dc.warnings, sourceLevel, new boolean[] {vararg_meth.giveUnchecked(client_meth), vararg_meth.giveVarargs(client_meth)}, source, trustMe, suppressLevelClient, suppressLevelDecl, modKind); } static void check(Set<Warning> warnings, SourceLevel sourceLevel, boolean[] warnArr, JavaSource source, TrustMe trustMe, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl, ModifierKind modKind) { boolean badOutput = false; for (Warning wkind : Warning.values()) { boolean isSuppressed = wkind.isSuppressed(trustMe, sourceLevel, suppressLevelClient, suppressLevelDecl, modKind); System.out.println("SUPPRESSED = " + isSuppressed); badOutput |= (warnArr[wkind.ordinal()] && !isSuppressed) != warnings.contains(wkind); } if (badOutput) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nExpected unchecked warning: " + warnArr[0] + "\nExpected unsafe vararg warning: " + warnArr[1] + "\nWarnings: " + warnings + "\nSource level: " + sourceLevel); } } static class JavaSource extends SimpleJavaFileObject { String source; public JavaSource(TrustMe trustMe, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl, ModifierKind modKind, Signature vararg_meth, Signature client_meth) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); String meth1 = vararg_meth.template.replace("#arity", "..."); meth1 = meth1.replace("#name", "m"); meth1 = meth1.replace("#body", ""); meth1 = trustMe.anno + "\n" + suppressLevelDecl.getSuppressAnno() + modKind.mod + meth1; String meth2 = client_meth.template.replace("#arity", ""); meth2 = meth2.replace("#name", "test"); meth2 = meth2.replace("#body", "m(arg);"); meth2 = suppressLevelClient.getSuppressAnno() + meth2; source = "import java.util.List;\n" + "class Test {\n" + meth1 + "\n" + meth2 + "\n}\n"; } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { Set<Warning> warnings = new HashSet<>(); public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.MANDATORY_WARNING || diagnostic.getKind() == Diagnostic.Kind.WARNING) { if (diagnostic.getCode().contains(Warning.VARARGS.key)) { warnings.add(Warning.VARARGS); } else if(diagnostic.getCode().contains(Warning.UNCHECKED.key)) { warnings.add(Warning.UNCHECKED); } } } } }
10,633
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/warning/Warn2.java
/* * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5035307 * @summary fixed-arity warning given too often * @author gafter * * @compile -Werror Warn2.java */ package varargs.warning.warn2; class Warn2 { void f(String... args) {} void g(String... args) { f(args); } }
1,316
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/warning/Warn1.java
/* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5035307 * @summary fixed-arity warning given too often * @author gafter * * @compile -Werror -source 1.4 -Xlint:-options Warn1.java */ package varargs.warning.warn1; import java.util.List; import java.util.Arrays; class Warn1 { void f(String[] args) { List l = java.util.Arrays.asList(args); } }
1,398
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/warning/Warn3.java
/* * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 5035307 * @summary fixed-arity warning given too often * @author gafter * * @compile -Werror Warn3.java */ package varargs.warning.warn3; class Warn3 { void f(Class<?>... args) {} void g(Class... args) { f(args); } }
1,317
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Warn5.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/warning/Warn5.java
/* * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6993978 7097436 * @summary Project Coin: Annotation to reduce varargs warnings * @author mcimadamore * @run main Warn5 */ import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.JavacTool; import java.net.URI; import java.util.Arrays; import java.util.EnumSet; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class Warn5 { enum XlintOption { NONE("none"), ALL("all"); String opt; XlintOption(String opt) { this.opt = opt; } String getXlintOption() { return "-Xlint:" + opt; } } enum TrustMe { DONT_TRUST(""), TRUST("@java.lang.SafeVarargs"); String anno; TrustMe(String anno) { this.anno = anno; } } enum SuppressLevel { NONE, VARARGS; String getSuppressAnno() { return this == VARARGS ? "@SuppressWarnings(\"varargs\")" : ""; } } enum ModifierKind { NONE(""), FINAL("final"), STATIC("static"); String mod; ModifierKind(String mod) { this.mod = mod; } } enum MethodKind { METHOD("void m"), CONSTRUCTOR("Test"); String name; MethodKind(String name) { this.name = name; } } enum SourceLevel { JDK_6("6"), JDK_7("7"); String sourceKey; SourceLevel(String sourceKey) { this.sourceKey = sourceKey; } } enum SignatureKind { VARARGS_X("#K <X>#N(X... x)", false, true), VARARGS_STRING("#K #N(String... x)", true, true), ARRAY_X("#K <X>#N(X[] x)", false, false), ARRAY_STRING("#K #N(String[] x)", true, false); String stub; boolean isReifiableArg; boolean isVarargs; SignatureKind(String stub, boolean isReifiableArg, boolean isVarargs) { this.stub = stub; this.isReifiableArg = isReifiableArg; this.isVarargs = isVarargs; } String getSignature(ModifierKind modKind, MethodKind methKind) { return methKind != MethodKind.CONSTRUCTOR ? stub.replace("#K", modKind.mod).replace("#N", methKind.name) : stub.replace("#K", "").replace("#N", methKind.name); } } enum BodyKind { ASSIGN("Object o = x;", true), CAST("Object o = (Object)x;", true), METH("test(x);", true), PRINT("System.out.println(x.toString());", false), ARRAY_ASSIGN("Object[] o = x;", true), ARRAY_CAST("Object[] o = (Object[])x;", true), ARRAY_METH("testArr(x);", true); String body; boolean hasAliasing; BodyKind(String body, boolean hasAliasing) { this.body = body; this.hasAliasing = hasAliasing; } } enum WarningKind { UNSAFE_BODY, UNSAFE_DECL, MALFORMED_SAFEVARARGS, REDUNDANT_SAFEVARARGS; } // Create a single file manager and reuse it for each compile to save time. static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); public static void main(String... args) throws Exception { for (SourceLevel sourceLevel : SourceLevel.values()) { for (XlintOption xlint : XlintOption.values()) { for (TrustMe trustMe : TrustMe.values()) { for (SuppressLevel suppressLevel : SuppressLevel.values()) { for (ModifierKind modKind : ModifierKind.values()) { for (MethodKind methKind : MethodKind.values()) { for (SignatureKind sig : SignatureKind.values()) { for (BodyKind body : BodyKind.values()) { new Warn5(sourceLevel, xlint, trustMe, suppressLevel, modKind, methKind, sig, body).test(); } } } } } } } } } final SourceLevel sourceLevel; final XlintOption xlint; final TrustMe trustMe; final SuppressLevel suppressLevel; final ModifierKind modKind; final MethodKind methKind; final SignatureKind sig; final BodyKind body; final JavaSource source; final DiagnosticChecker dc; public Warn5(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) { this.sourceLevel = sourceLevel; this.xlint = xlint; this.trustMe = trustMe; this.suppressLevel = suppressLevel; this.modKind = modKind; this.methKind = methKind; this.sig = sig; this.body = body; this.source = new JavaSource(); this.dc = new DiagnosticChecker(); } void test() throws Exception { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, fm, dc, Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source)); ct.analyze(); check(); } void check() { EnumSet<WarningKind> expectedWarnings = EnumSet.noneOf(WarningKind.class); if (sourceLevel == SourceLevel.JDK_7 && trustMe == TrustMe.TRUST && suppressLevel != SuppressLevel.VARARGS && xlint != XlintOption.NONE && sig.isVarargs && !sig.isReifiableArg && body.hasAliasing && (methKind == MethodKind.CONSTRUCTOR || (methKind == MethodKind.METHOD && modKind != ModifierKind.NONE))) { expectedWarnings.add(WarningKind.UNSAFE_BODY); } if (sourceLevel == SourceLevel.JDK_7 && trustMe == TrustMe.DONT_TRUST && sig.isVarargs && !sig.isReifiableArg && xlint == XlintOption.ALL) { expectedWarnings.add(WarningKind.UNSAFE_DECL); } if (sourceLevel == SourceLevel.JDK_7 && trustMe == TrustMe.TRUST && (!sig.isVarargs || (modKind == ModifierKind.NONE && methKind == MethodKind.METHOD))) { expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS); } if (sourceLevel == SourceLevel.JDK_7 && trustMe == TrustMe.TRUST && xlint != XlintOption.NONE && suppressLevel != SuppressLevel.VARARGS && (modKind != ModifierKind.NONE || methKind == MethodKind.CONSTRUCTOR) && sig.isVarargs && sig.isReifiableArg) { expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS); } if (!expectedWarnings.containsAll(dc.warnings) || !dc.warnings.containsAll(expectedWarnings)) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nOptions: " + xlint.getXlintOption() + "\nExpected warnings: " + expectedWarnings + "\nFound warnings: " + dc.warnings); } } class JavaSource extends SimpleJavaFileObject { String template = "import com.sun.tools.javac.api.*;\n" + "import java.util.List;\n" + "class Test {\n" + " static void test(Object o) {}\n" + " static void testArr(Object[] o) {}\n" + " #T \n #S #M { #B }\n" + "}\n"; String source; public JavaSource() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = template.replace("#T", trustMe.anno). replace("#S", suppressLevel.getSuppressAnno()). replace("#M", sig.getSignature(modKind, methKind)). replace("#B", body.body); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { EnumSet<WarningKind> warnings = EnumSet.noneOf(WarningKind.class); public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.WARNING) { if (diagnostic.getCode().contains("unsafe.use.varargs.param")) { setWarning(WarningKind.UNSAFE_BODY); } else if (diagnostic.getCode().contains("redundant.trustme")) { setWarning(WarningKind.REDUNDANT_SAFEVARARGS); } } else if (diagnostic.getKind() == Diagnostic.Kind.MANDATORY_WARNING && diagnostic.getCode().contains("varargs.non.reifiable.type")) { setWarning(WarningKind.UNSAFE_DECL); } else if (diagnostic.getKind() == Diagnostic.Kind.ERROR && diagnostic.getCode().contains("invalid.trustme")) { setWarning(WarningKind.MALFORMED_SAFEVARARGS); } } void setWarning(WarningKind wk) { if (!warnings.add(wk)) { throw new AssertionError("Duplicate warning of kind " + wk + " in source:\n" + source); } } boolean hasWarning(WarningKind wk) { return warnings.contains(wk); } } }
11,358
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7043922.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/7043922/T7043922.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 7043922 * @summary Regression: internal compiler error for nested anonymous inner class featuring varargs constructor */ import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.List; import java.net.URI; import java.util.Arrays; import java.util.Locale; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class T7043922 { ClassKind[] classKinds; ConstructorKind[] constructorKinds; T7043922(ClassKind[] classKinds, ConstructorKind[] constructorKinds) { this.classKinds = classKinds; this.constructorKinds = constructorKinds; } void compileAndCheck() throws Exception { JavaSource source = new JavaSource(); ErrorChecker ec = new ErrorChecker(); JavacTask ct = (JavacTask)tool.getTask(null, fm, ec, null, null, Arrays.asList(source)); ct.analyze(); if (ec.errorFound) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nCompiler diagnostics:\n" + ec.printDiags()); } } class JavaSource extends SimpleJavaFileObject { static final String source_template = "#C0 A0 { #K0 }\n" + "#C1 A1 { #K1 }\n" + "#C2 A2 { #K2 }\n" + "class D {\n" + " void test() {\n" + " new A0(#V0) {\n" + " void test() {\n" + " new A1(#V1) {\n" + " void test() {\n" + " new A2(#V2) {};\n" + " }\n" + " };\n" + " }\n" + " };\n" + " }\n" + "}\n"; String source; public JavaSource() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = source_template; for (int i = 0; i < 3; i++) { source = source.replaceAll("#C" + i, classKinds[i].classKind). replaceAll("#K" + i, classKinds[i].getConstructor("A" + i, constructorKinds[i])). replaceAll("#V" + i, constructorKinds[i].constrArgs); } } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } /** global decls ***/ enum ConstructorKind { DEFAULT("", ""), FIXED_ARITY("String s", "\"\""), VARIABLE_ARITY("String... ss", "\"\",\"\""); String constrParam; String constrArgs; private ConstructorKind(String constrParam, String constrArgs) { this.constrParam = constrParam; this.constrArgs = constrArgs; } } enum ClassKind { ABSTRACT("abstract class"), CLASS("class"), INTERFACE("interface"); String classKind; private ClassKind(String classKind) { this.classKind = classKind; } boolean isConstructorOk(ConstructorKind ck) { return this != INTERFACE || ck == ConstructorKind.DEFAULT; } String getConstructor(String className, ConstructorKind ck) { return this == INTERFACE ? "" : (className + "(" + ck.constrParam + ") {}"); } } // Create a single file manager and JavaCompiler tool // and reuse them for each compile to save time. static final StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); public static void main(String... args) throws Exception { for (ClassKind classKind1 : ClassKind.values()) { for (ConstructorKind constrKind1 : ConstructorKind.values()) { if (!classKind1.isConstructorOk(constrKind1)) continue; for (ClassKind classKind2 : ClassKind.values()) { for (ConstructorKind constrKind2 : ConstructorKind.values()) { if (!classKind2.isConstructorOk(constrKind2)) continue; for (ClassKind classKind3 : ClassKind.values()) { for (ConstructorKind constrKind3 : ConstructorKind.values()) { if (!classKind3.isConstructorOk(constrKind3)) continue; new T7043922(new ClassKind[] { classKind1, classKind2, classKind3 }, new ConstructorKind[] { constrKind1, constrKind2, constrKind3 }).compileAndCheck(); } } } } } } } static class ErrorChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean errorFound; List<String> errDiags = List.nil(); public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { errDiags = errDiags.append(diagnostic.getMessage(Locale.getDefault())); errorFound = true; } } String printDiags() { StringBuilder buf = new StringBuilder(); for (String s : errDiags) { buf.append(s); buf.append("\n"); } return buf.toString(); } } }
7,263
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6730476b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/6730476/T6730476b.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6730476 * * @summary invalid "unchecked generic array" warning * @author mcimadamore * @compile T6730476b.java -Xlint -Werror * */ class T6730476b { java.util.List<Integer> ints = java.util.Arrays.asList(); }
1,292
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6730476a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/6730476/T6730476a.java
/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6730476 * * @summary invalid "unchecked generic array" warning * @author mcimadamore * @compile T6730476a.java -Xlint:unchecked -Werror * */ class T6730476a { @SuppressWarnings("unchecked") <T> void f(int i, T ... x) {} void g() { f(1); } }
1,342
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6806876.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/6806876/T6806876.java
/* * @test /nodynamiccopyright/ * @bug 6806876 * @author mcimadamore * @summary ClassCastException occurs in assignment expressions without any heap pollutions * @compile/fail/ref=T6806876.out -Xlint:unchecked -Werror -XDrawDiagnostics T6806876.java */ class T6806876 { void test(Integer i, Long l) { Comparable<?>[] res = m(i, l); } <T> T[] m(T...a) { return null; } }
415
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7042566.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/7042566/T7042566.java
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 7042566 * @summary Unambiguous varargs method calls flagged as ambiguous */ import com.sun.source.util.JavacTask; import com.sun.tools.classfile.Instruction; import com.sun.tools.classfile.Attribute; import com.sun.tools.classfile.ClassFile; import com.sun.tools.classfile.Code_attribute; import com.sun.tools.classfile.ConstantPool.*; import com.sun.tools.classfile.Method; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.List; import java.io.File; import java.net.URI; import java.util.Arrays; import java.util.Locale; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class T7042566 { VarargsMethod m1; VarargsMethod m2; TypeConfiguration actuals; T7042566(TypeConfiguration m1_conf, TypeConfiguration m2_conf, TypeConfiguration actuals) { this.m1 = new VarargsMethod(m1_conf); this.m2 = new VarargsMethod(m2_conf); this.actuals = actuals; } void compileAndCheck() throws Exception { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaSource source = new JavaSource(); ErrorChecker ec = new ErrorChecker(); JavacTask ct = (JavacTask)tool.getTask(null, fm, ec, null, null, Arrays.asList(source)); ct.call(); check(source, ec); } void check(JavaSource source, ErrorChecker ec) { checkCount++; boolean resolutionError = false; VarargsMethod selectedMethod = null; boolean m1_applicable = m1.isApplicable(actuals); boolean m2_applicable = m2.isApplicable(actuals); if (!m1_applicable && !m2_applicable) { resolutionError = true; } else if (m1_applicable && m2_applicable) { //most specific boolean m1_moreSpecific = m1.isMoreSpecificThan(m2); boolean m2_moreSpecific = m2.isMoreSpecificThan(m1); resolutionError = m1_moreSpecific == m2_moreSpecific; selectedMethod = m1_moreSpecific ? m1 : m2; } else { selectedMethod = m1_applicable ? m1 : m2; } if (ec.errorFound != resolutionError) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nExpected resolution error: " + resolutionError + "\nFound error: " + ec.errorFound + "\nCompiler diagnostics:\n" + ec.printDiags()); } else if (!resolutionError) { verifyBytecode(selectedMethod, source); } } void verifyBytecode(VarargsMethod selected, JavaSource source) { bytecodeCheckCount++; File compiledTest = new File("Test.class"); try { ClassFile cf = ClassFile.read(compiledTest); Method testMethod = null; for (Method m : cf.methods) { if (m.getName(cf.constant_pool).equals("test")) { testMethod = m; break; } } if (testMethod == null) { throw new Error("Test method not found"); } Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code); if (testMethod == null) { throw new Error("Code attribute for test() method not found"); } for (Instruction i : ea.getInstructions()) { if (i.getMnemonic().equals("invokevirtual")) { int cp_entry = i.getUnsignedShort(1); CONSTANT_Methodref_info methRef = (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry); String type = methRef.getNameAndTypeInfo().getType(); String sig = selected.parameterTypes.bytecodeSigStr; if (!type.contains(sig)) { throw new Error("Unexpected type method call: " + type + "" + "\nfound: " + sig + "\n" + source.getCharContent(true)); } break; } } } catch (Exception e) { e.printStackTrace(); throw new Error("error reading " + compiledTest +": " + e); } } class JavaSource extends SimpleJavaFileObject { static final String source_template = "class Test {\n" + " #V1\n" + " #V2\n" + " void test() { m(#E); }\n" + "}"; String source; public JavaSource() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = source_template.replaceAll("#V1", m1.toString()). replaceAll("#V2", m2.toString()). replaceAll("#E", actuals.expressionListStr); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } /** global decls ***/ // Create a single file manager and reuse it for each compile to save time. static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); //statistics static int checkCount = 0; static int bytecodeCheckCount = 0; public static void main(String... args) throws Exception { for (TypeConfiguration tconf1 : TypeConfiguration.values()) { for (TypeConfiguration tconf2 : TypeConfiguration.values()) { for (TypeConfiguration tconf3 : TypeConfiguration.values()) { new T7042566(tconf1, tconf2, tconf3).compileAndCheck(); } } } System.out.println("Total checks made: " + checkCount); System.out.println("Bytecode checks made: " + bytecodeCheckCount); } enum TypeKind { OBJECT("Object", "(Object)null", "Ljava/lang/Object;"), STRING("String", "(String)null", "Ljava/lang/String;"); String typeString; String valueString; String bytecodeString; TypeKind(String typeString, String valueString, String bytecodeString) { this.typeString = typeString; this.valueString = valueString; this.bytecodeString = bytecodeString; } boolean isSubtypeOf(TypeKind that) { return that == OBJECT || (that == STRING && this == STRING); } } enum TypeConfiguration { A(TypeKind.OBJECT), B(TypeKind.STRING), AA(TypeKind.OBJECT, TypeKind.OBJECT), AB(TypeKind.OBJECT, TypeKind.STRING), BA(TypeKind.STRING, TypeKind.OBJECT), BB(TypeKind.STRING, TypeKind.STRING), AAA(TypeKind.OBJECT, TypeKind.OBJECT, TypeKind.OBJECT), AAB(TypeKind.OBJECT, TypeKind.OBJECT, TypeKind.STRING), ABA(TypeKind.OBJECT, TypeKind.STRING, TypeKind.OBJECT), ABB(TypeKind.OBJECT, TypeKind.STRING, TypeKind.STRING), BAA(TypeKind.STRING, TypeKind.OBJECT, TypeKind.OBJECT), BAB(TypeKind.STRING, TypeKind.OBJECT, TypeKind.STRING), BBA(TypeKind.STRING, TypeKind.STRING, TypeKind.OBJECT), BBB(TypeKind.STRING, TypeKind.STRING, TypeKind.STRING); List<TypeKind> typeKindList; String expressionListStr; String parameterListStr; String bytecodeSigStr; private TypeConfiguration(TypeKind... typeKindList) { this.typeKindList = List.from(typeKindList); expressionListStr = asExpressionList(); parameterListStr = asParameterList(); bytecodeSigStr = asBytecodeString(); } private String asExpressionList() { StringBuilder buf = new StringBuilder(); String sep = ""; for (TypeKind tk : typeKindList) { buf.append(sep); buf.append(tk.valueString); sep = ","; } return buf.toString(); } private String asParameterList() { StringBuilder buf = new StringBuilder(); String sep = ""; int count = 0; for (TypeKind arg : typeKindList) { buf.append(sep); buf.append(arg.typeString); if (count == (typeKindList.size() - 1)) { buf.append("..."); } buf.append(" "); buf.append("arg" + count++); sep = ","; } return buf.toString(); } private String asBytecodeString() { StringBuilder buf = new StringBuilder(); int count = 0; for (TypeKind arg : typeKindList) { if (count == (typeKindList.size() - 1)) { buf.append("["); } buf.append(arg.bytecodeString); count++; } return buf.toString(); } } static class VarargsMethod { TypeConfiguration parameterTypes; public VarargsMethod(TypeConfiguration parameterTypes) { this.parameterTypes = parameterTypes; } @Override public String toString() { return "void m( " + parameterTypes.parameterListStr + ") {}"; } boolean isApplicable(TypeConfiguration that) { List<TypeKind> actuals = that.typeKindList; List<TypeKind> formals = parameterTypes.typeKindList; if ((actuals.size() - formals.size()) < -1) return false; //not enough args for (TypeKind actual : actuals) { if (!actual.isSubtypeOf(formals.head)) return false; //type mismatch formals = formals.tail.isEmpty() ? formals : formals.tail; } return true; } boolean isMoreSpecificThan(VarargsMethod that) { List<TypeKind> actuals = parameterTypes.typeKindList; List<TypeKind> formals = that.parameterTypes.typeKindList; int checks = 0; int expectedCheck = Math.max(actuals.size(), formals.size()); while (checks < expectedCheck) { if (!actuals.head.isSubtypeOf(formals.head)) return false; //type mismatch formals = formals.tail.isEmpty() ? formals : formals.tail; actuals = actuals.tail.isEmpty() ? actuals : actuals.tail; checks++; } return true; } } static class ErrorChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean errorFound; List<String> errDiags = List.nil(); public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { errDiags = errDiags.append(diagnostic.getMessage(Locale.getDefault())); errorFound = true; } } String printDiags() { StringBuilder buf = new StringBuilder(); for (String s : errDiags) { buf.append(s); buf.append("\n"); } return buf.toString(); } } }
12,683
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6199075.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/varargs/6199075/T6199075.java
/* * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 6199075 * * @summary Unambiguous varargs method calls flagged as ambiguous * @author mcimadamore * */ import com.sun.source.util.JavacTask; import com.sun.tools.classfile.Instruction; import com.sun.tools.classfile.Attribute; import com.sun.tools.classfile.ClassFile; import com.sun.tools.classfile.Code_attribute; import com.sun.tools.classfile.ConstantPool.*; import com.sun.tools.classfile.Method; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.List; import java.io.File; import java.net.URI; import java.util.Arrays; import java.util.Locale; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class T6199075 { int checkCount = 0; int bytecodeCheckCount = 0; enum TypeKind { BYTE("byte", "(byte)1", "[B", 0), CHAR("char", "'c'", "[C", 1), SHORT("short", "(short)1", "[S", 2), INT("int", "1", "[I", 3), LONG("long", "1L", "[J", 4), FLOAT("float", "1.0F", "[F", 5), DOUBLE("double", "1.0D", "[D", 6), BOOLEAN("boolean", "true", "[Z", -1); String typeString; String valueString; String bytecodeString; private int subtypeTag; TypeKind(String typeString, String valueString, String bytecodeString, int subtypeTag) { this.typeString = typeString; this.valueString = valueString; this.bytecodeString = bytecodeString; this.subtypeTag = subtypeTag; } boolean isSubtypeOf(TypeKind that) { switch (this) { case BOOLEAN: return that == BOOLEAN; case BYTE: case CHAR: return this.subtypeTag == that.subtypeTag || this.subtypeTag + 2 <= that.subtypeTag; default: return this.subtypeTag <= that.subtypeTag; } } } enum ArgumentsArity { ZERO(0), ONE(1), TWO(2), THREE(3); int arity; ArgumentsArity(int arity) { this.arity = arity; } String asExpressionList(TypeKind type) { StringBuilder buf = new StringBuilder(); String sep = ""; for (int i = 0; i < arity; i++) { buf.append(sep); buf.append(type.valueString); sep = ","; } return buf.toString(); } } static class VarargsMethod { TypeKind varargsElement; VarargsMethod(TypeKind varargsElement) { this.varargsElement = varargsElement; } @Override public String toString() { return "void m("+ varargsElement.typeString+ "... args) {}"; } boolean isApplicable(TypeKind actual, ArgumentsArity argsArity) { return argsArity == ArgumentsArity.ZERO || actual.isSubtypeOf(varargsElement); } boolean isMoreSpecificThan(VarargsMethod that) { return varargsElement.isSubtypeOf(that.varargsElement); } } public static void main(String... args) throws Exception { new T6199075().test(); } void test() throws Exception { for (TypeKind formal1 : TypeKind.values()) { VarargsMethod m1 = new VarargsMethod(formal1); for (TypeKind formal2 : TypeKind.values()) { VarargsMethod m2 = new VarargsMethod(formal2); for (TypeKind actual : TypeKind.values()) { for (ArgumentsArity argsArity : ArgumentsArity.values()) { compileAndCheck(m1, m2, actual, argsArity); } } } } System.out.println("Total checks made: " + checkCount); System.out.println("Bytecode checks made: " + bytecodeCheckCount); } // Create a single file manager and reuse it for each compile to save time. StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaSource source = new JavaSource(m1, m2, actual, argsArity); ErrorChecker ec = new ErrorChecker(); JavacTask ct = (JavacTask)tool.getTask(null, fm, ec, null, null, Arrays.asList(source)); ct.generate(); check(source, ec, m1, m2, actual, argsArity); } void check(JavaSource source, ErrorChecker ec, VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) { checkCount++; boolean resolutionError = false; VarargsMethod selectedMethod = null; boolean m1_applicable = m1.isApplicable(actual, argsArity); boolean m2_applicable = m2.isApplicable(actual, argsArity); if (!m1_applicable && !m2_applicable) { resolutionError = true; } else if (m1_applicable && m2_applicable) { //most specific boolean m1_moreSpecific = m1.isMoreSpecificThan(m2); boolean m2_moreSpecific = m2.isMoreSpecificThan(m1); resolutionError = m1_moreSpecific == m2_moreSpecific; selectedMethod = m1_moreSpecific ? m1 : m2; } else { selectedMethod = m1_applicable ? m1 : m2; } if (ec.errorFound != resolutionError) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nExpected resolution error: " + resolutionError + "\nFound error: " + ec.errorFound + "\nCompiler diagnostics:\n" + ec.printDiags()); } else if (!resolutionError) { verifyBytecode(selectedMethod); } } void verifyBytecode(VarargsMethod selected) { bytecodeCheckCount++; File compiledTest = new File("Test.class"); try { ClassFile cf = ClassFile.read(compiledTest); Method testMethod = null; for (Method m : cf.methods) { if (m.getName(cf.constant_pool).equals("test")) { testMethod = m; break; } } if (testMethod == null) { throw new Error("Test method not found"); } Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code); if (testMethod == null) { throw new Error("Code attribute for test() method not found"); } for (Instruction i : ea.getInstructions()) { if (i.getMnemonic().equals("invokevirtual")) { int cp_entry = i.getUnsignedShort(1); CONSTANT_Methodref_info methRef = (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry); String type = methRef.getNameAndTypeInfo().getType(); if (!type.contains(selected.varargsElement.bytecodeString)) { throw new Error("Unexpected type method call: " + type); } break; } } } catch (Exception e) { e.printStackTrace(); throw new Error("error reading " + compiledTest +": " + e); } } static class JavaSource extends SimpleJavaFileObject { static final String source_template = "class Test {\n" + " #V1\n" + " #V2\n" + " void test() { m(#E); }\n" + "}"; String source; public JavaSource(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = source_template.replaceAll("#V1", m1.toString()). replaceAll("#V2", m2.toString()). replaceAll("#E", argsArity.asExpressionList(actual)); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } static class ErrorChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean errorFound; List<String> errDiags = List.nil(); public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { errDiags = errDiags.append(diagnostic.getMessage(Locale.getDefault())); errorFound = true; } } String printDiags() { StringBuilder buf = new StringBuilder(); for (String s : errDiags) { buf.append(s); buf.append("\n"); } return buf.toString(); } } }
10,265
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z