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
ProtectedMemberAccess2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess2.java
/* * @test /nodynamiccopyright/ * @bug 4319507 4785453 * @summary Verify correct implementation of JLS2e 6.6.2.1 * @author maddox * * @compile/fail/ref=ProtectedMemberAccess2.out -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess2.java */ // 71 errors expected. import pkg.SuperClass; class ProtectedMemberAccess2 { // Since this class is not a subclass of the class in which the // protected members are declared, all of the accesses are illegal. pkg.SuperClass x = new pkg.SuperClass(); static pkg.SuperClass sx = new pkg.SuperClass(); int i = x.pi; // illegal int j = x.spi; // illegal int n = sx.pi; // illegal int m = sx.spi; // illegal static int sn = sx.pi; // illegal static int sm = sx.spi; // illegal int w = x.pm(); // illegal int y = x.spm(); // illegal int u = sx.pm(); // illegal int v = sx.spm(); // illegal pkg.SuperClass.pC obj1; // illegal pkg.SuperClass.spC obj2; // illegal pkg.SuperClass.pI obj3; // illegal pkg.SuperClass.spI obj4; // illegal Object o1 = (pkg.SuperClass.pC) null; // illegal Object o2 = (pkg.SuperClass.spC) null; // illegal Object o3 = (pkg.SuperClass.pI) null; // illegal Object o4 = (pkg.SuperClass.spI) null; // illegal class C1 extends pkg.SuperClass.pC {} // illegal class C2 extends pkg.SuperClass.spC {} // illegal interface I1 extends pkg.SuperClass.pI {} // illegal interface I2 extends pkg.SuperClass.spI {} // illegal static { pkg.SuperClass lx = new pkg.SuperClass(); sx.pi = 1; // illegal sx.spi = 2; // illegal lx.pi = 1; // illegal lx.spi = 2; // illegal int n = sx.pi; // illegal int m = sx.spi; // illegal int k = lx.pi; // illegal int l = lx.spi; // illegal int u = sx.pm(); // illegal int v = sx.spm(); // illegal int w = lx.pm(); // illegal int z = lx.spm(); // illegal pkg.SuperClass.pC obj1; // illegal pkg.SuperClass.spC obj2; // illegal pkg.SuperClass.pI obj3; // illegal pkg.SuperClass.spI obj4; // illegal Object o1 = (pkg.SuperClass.pC) null; // illegal Object o2 = (pkg.SuperClass.spC) null; // illegal Object o3 = (pkg.SuperClass.pI) null; // illegal Object o4 = (pkg.SuperClass.spI) null; // illegal //class C1 extends pkg.SuperClass.pC {} class C2 extends pkg.SuperClass.spC {} // illegal //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } void m() { pkg.SuperClass lx = new pkg.SuperClass(); x.pi = 1; // illegal x.spi = 2; // illegal sx.pi = 1; // illegal sx.spi = 2; // illegal lx.pi = 1; // illegal lx.spi = 2; // illegal int t = x.pm(); // illegal int y = x.spm(); // illegal int u = sx.pm(); // illegal int v = sx.spm(); // illegal int w = lx.pm(); // illegal int z = lx.spm(); // illegal int i = x.pi; // illegal int j = x.spi; // illegal int n = sx.pi; // illegal int m = sx.spi; // illegal int k = lx.pi; // illegal int l = lx.spi; // illegal pkg.SuperClass.pC obj1; // illegal pkg.SuperClass.spC obj2; // illegal pkg.SuperClass.pI obj3; // illegal pkg.SuperClass.spI obj4; // illegal Object o1 = (pkg.SuperClass.pC) null; // illegal Object o2 = (pkg.SuperClass.spC) null; // illegal Object o3 = (pkg.SuperClass.pI) null; // illegal Object o4 = (pkg.SuperClass.spI) null; // illegal class C1 extends pkg.SuperClass.pC {} // illegal class C2 extends pkg.SuperClass.spC {} // illegal //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } }
5,177
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ProtectedMemberAccess3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess3.java
/* * @test /nodynamiccopyright/ * @bug 4319507 4785453 * @summary Verify correct implementation of JLS2e 6.6.2.1 * @author maddox * * @compile/fail/ref=ProtectedMemberAccess3.out -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess3.java */ // 46 errors expected. import pkg.SuperClass; class ProtectedMemberAccess3 { // Since this class is not a subclass of the class in which the // protected members are declared, all of the accesses are illegal. pkg.SuperClass x = new pkg.SuperClass(); static pkg.SuperClass sx = new pkg.SuperClass(); class Inner { int i = x.pi; // illegal int j = x.spi; // illegal int n = sx.pi; // illegal int m = sx.spi; // illegal //static int sn = sx.pi; //static int sm = sx.spi; int w = x.pm(); // illegal int y = x.spm(); // illegal int u = sx.pm(); // illegal int v = sx.spm(); // illegal pkg.SuperClass.pC obj1; // illegal pkg.SuperClass.spC obj2; // illegal pkg.SuperClass.pI obj3; // illegal pkg.SuperClass.spI obj4; // illegal Object o1 = (pkg.SuperClass.pC) null; // illegal Object o2 = (pkg.SuperClass.spC) null; // illegal Object o3 = (pkg.SuperClass.pI) null; // illegal Object o4 = (pkg.SuperClass.spI) null; // illegal class C1 extends pkg.SuperClass.pC {} // illegal class C2 extends pkg.SuperClass.spC {} // illegal //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} // Not allowed in inner classes. // static { ... } void m() { pkg.SuperClass lx = new pkg.SuperClass(); x.pi = 1; // illegal x.spi = 2; // illegal sx.pi = 1; // illegal sx.spi = 2; // illegal lx.pi = 1; // illegal lx.spi = 2; // illegal int t = x.pm(); // illegal int y = x.spm(); // illegal int u = sx.pm(); // illegal int v = sx.spm(); // illegal int w = lx.pm(); // illegal int z = lx.spm(); // illegal int i = x.pi; // illegal int j = x.spi; // illegal int n = sx.pi; // illegal int m = sx.spi; // illegal int k = lx.pi; // illegal int l = lx.spi; // illegal pkg.SuperClass.pC obj1; // illegal pkg.SuperClass.spC obj2; // illegal pkg.SuperClass.pI obj3; // illegal pkg.SuperClass.spI obj4; // illegal Object o1 = (pkg.SuperClass.pC) null; // illegal Object o2 = (pkg.SuperClass.spC) null; // illegal Object o3 = (pkg.SuperClass.pI) null; // illegal Object o4 = (pkg.SuperClass.spI) null; // illegal class C1 extends pkg.SuperClass.pC {} // illegal class C2 extends pkg.SuperClass.spC {} // illegal //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } } }
3,733
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ProtectedMemberAccess1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess1.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 4319507 * @summary Verify correct implementation of JLS2e 6.6.2.1 * @author maddox * * @run compile ProtectedMemberAccess1.java */ import pkg.SuperClass; class ProtectedMemberAccess1a extends SuperClass { // Access to a protected member via its simple name // is always legal in a subclass of the class in // which the member is declared. int i = pi; int j = spi; int x = pm(); int y = spm(); pC obj1; spC obj2; pI obj3; spI obj4; Object o1 = (pC) null; Object o2 = (spC) null; Object o3 = (pI) null; Object o4 = (spI) null; class C1 extends pC {} class C2 extends spC {} interface I1 extends pI {} interface I2 extends spI {} static { spi = 2; int y = spm(); pC obj1; spC obj2; pI obj3; spI obj4; Object o1 = (pC) null; Object o2 = (spC) null; Object o3 = (pI) null; Object o4 = (spI) null; //class C1 extends pC {} class C2 extends spC {} //interface I1 extends pI {} //interface I2 extends spI {} } void m() { pi = 1; spi = 2; int x = pm(); int y = spm(); pC obj1; spC obj2; pI obj3; spI obj4; Object o1 = (pC) null; Object o2 = (spC) null; Object o3 = (pI) null; Object o4 = (spI) null; class C1 extends pC {} class C2 extends spC {} //interface I1 extends pI {} //interface I2 extends spI {} } class Inner { int i = pi; int j = spi; int x = pm(); int y = spm(); pC obj1; spC obj2; pI obj3; spI obj4; Object o1 = (pC) null; Object o2 = (spC) null; Object o3 = (pI) null; Object o4 = (spI) null; class C1 extends pC {} class C2 extends spC {} //interface I1 extends pI {} //interface I2 extends spI {} // Not allowed in inner classes. // static { ... } void m() { pi = 1; spi = 2; int x = pm(); int y = spm(); pC obj1; spC obj2; pI obj3; spI obj4; Object o1 = (pC) null; Object o2 = (spC) null; Object o3 = (pI) null; Object o4 = (spI) null; class C1 extends pC {} class C2 extends spC {} //interface I1 extends pI {} //interface I2 extends spI {} } } } class ProtectedMemberAccess2a extends pkg.SuperClass { // Access to a protected instance (non-static) field, instance method, // or member type by a qualified name is always legal in a subclass of // the class in which the member is declared. Such access to a protected // instance field or instance method is allowed if the qualifying type // or the type of the qualifying expression is (a subclass of) the class // in which the reference occurs. ProtectedMemberAccess2a x = new ProtectedMemberAccess2a(); static ProtectedMemberAccess2a sx = new ProtectedMemberAccess2a(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; static int sn = sx.pi; static int sm = sx.spi; int w = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); ProtectedMemberAccess2a.pC obj1; ProtectedMemberAccess2a.spC obj2; ProtectedMemberAccess2a.pI obj3; ProtectedMemberAccess2a.spI obj4; Object o1 = (ProtectedMemberAccess2a.pC) null; Object o2 = (ProtectedMemberAccess2a.spC) null; Object o3 = (ProtectedMemberAccess2a.pI) null; Object o4 = (ProtectedMemberAccess2a.spI) null; class C1 extends ProtectedMemberAccess2a.pC {} class C2 extends ProtectedMemberAccess2a.spC {} interface I1 extends ProtectedMemberAccess2a.pI {} interface I2 extends ProtectedMemberAccess2a.spI {} static { ProtectedMemberAccess2a lx = new ProtectedMemberAccess2a(); sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); ProtectedMemberAccess2a.pC obj1; ProtectedMemberAccess2a.spC obj2; ProtectedMemberAccess2a.pI obj3; ProtectedMemberAccess2a.spI obj4; Object o1 = (ProtectedMemberAccess2a.pC) null; Object o2 = (ProtectedMemberAccess2a.spC) null; Object o3 = (ProtectedMemberAccess2a.pI) null; Object o4 = (ProtectedMemberAccess2a.spI) null; //class C1 extends ProtectedMemberAccess2a.pC {} class C2 extends ProtectedMemberAccess2a.spC {} //interface I1 extends ProtectedMemberAccess2a.pI {} //interface I2 extends ProtectedMemberAccess2a.spI {} } void m() { ProtectedMemberAccess2a lx = new ProtectedMemberAccess2a(); x.pi = 1; x.spi = 2; sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int t = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; ProtectedMemberAccess2a.pC obj1; ProtectedMemberAccess2a.spC obj2; ProtectedMemberAccess2a.pI obj3; ProtectedMemberAccess2a.spI obj4; Object o1 = (ProtectedMemberAccess2a.pC) null; Object o2 = (ProtectedMemberAccess2a.spC) null; Object o3 = (ProtectedMemberAccess2a.pI) null; Object o4 = (ProtectedMemberAccess2a.spI) null; class C1 extends ProtectedMemberAccess2a.pC {} class C2 extends ProtectedMemberAccess2a.spC {} //interface I1 extends ProtectedMemberAccess2a.pI {} //interface I2 extends ProtectedMemberAccess2a.spI {} } class Inner { int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; //static int sn = sx.pi; //static int sm = sx.spi; int w = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); ProtectedMemberAccess2a.pC obj1; ProtectedMemberAccess2a.spC obj2; ProtectedMemberAccess2a.pI obj3; ProtectedMemberAccess2a.spI obj4; Object o1 = (ProtectedMemberAccess2a.pC) null; Object o2 = (ProtectedMemberAccess2a.spC) null; Object o3 = (ProtectedMemberAccess2a.pI) null; Object o4 = (ProtectedMemberAccess2a.spI) null; class C1 extends ProtectedMemberAccess2a.pC {} class C2 extends ProtectedMemberAccess2a.spC {} //interface I1 extends ProtectedMemberAccess2a.pI {} //interface I2 extends ProtectedMemberAccess2a.spI {} // Not allowed in inner classes. // static { ... } void m() { ProtectedMemberAccess2a lx = new ProtectedMemberAccess2a(); x.pi = 1; x.spi = 2; sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int t = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; ProtectedMemberAccess2a.pC obj1; ProtectedMemberAccess2a.spC obj2; ProtectedMemberAccess2a.pI obj3; ProtectedMemberAccess2a.spI obj4; Object o1 = (ProtectedMemberAccess2a.pC) null; Object o2 = (ProtectedMemberAccess2a.spC) null; Object o3 = (ProtectedMemberAccess2a.pI) null; Object o4 = (ProtectedMemberAccess2a.spI) null; class C1 extends ProtectedMemberAccess2a.pC {} class C2 extends ProtectedMemberAccess2a.spC {} //interface I1 extends ProtectedMemberAccess2a.pI {} //interface I2 extends ProtectedMemberAccess2a.spI {} } } } class SubClass extends ProtectedMemberAccess3a { } class ProtectedMemberAccess3a extends pkg.SuperClass { // Access to a protected instance (non-static) field, instance method, // or member type by a qualified name is always legal in a subclass of // the class in which the member is declared. Such access to a protected // instance field or instance method is allowed if the qualifying type // or the type of the qualifying expression is (a subclass of) the class // in which the reference occurs. SubClass x = new SubClass(); static SubClass sx = new SubClass(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; static int sn = sx.pi; static int sm = sx.spi; int w = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); SubClass.pC obj1; SubClass.spC obj2; SubClass.pI obj3; SubClass.spI obj4; Object o1 = (SubClass.pC) null; Object o2 = (SubClass.spC) null; Object o3 = (SubClass.pI) null; Object o4 = (SubClass.spI) null; class C1 extends SubClass.pC {} class C2 extends SubClass.spC {} interface I1 extends SubClass.pI {} interface I2 extends SubClass.spI {} static { SubClass lx = new SubClass(); sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); SubClass.pC obj1; SubClass.spC obj2; SubClass.pI obj3; SubClass.spI obj4; Object o1 = (SubClass.pC) null; Object o2 = (SubClass.spC) null; Object o3 = (SubClass.pI) null; Object o4 = (SubClass.spI) null; //class C1 extends SubClass.pC {} class C2 extends SubClass.spC {} //interface I1 extends SubClass.pI {} //interface I2 extends SubClass.spI {} } void m() { SubClass lx = new SubClass(); x.pi = 1; x.spi = 2; sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int t = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; SubClass.pC obj1; SubClass.spC obj2; SubClass.pI obj3; SubClass.spI obj4; Object o1 = (SubClass.pC) null; Object o2 = (SubClass.spC) null; Object o3 = (SubClass.pI) null; Object o4 = (SubClass.spI) null; class C1 extends SubClass.pC {} class C2 extends SubClass.spC {} //interface I1 extends SubClass.pI {} //interface I2 extends SubClass.spI {} } class Inner { int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; //static int sn = sx.pi; //static int sm = sx.spi; int w = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); SubClass.pC obj1; SubClass.spC obj2; SubClass.pI obj3; SubClass.spI obj4; Object o1 = (SubClass.pC) null; Object o2 = (SubClass.spC) null; Object o3 = (SubClass.pI) null; Object o4 = (SubClass.spI) null; class C1 extends SubClass.pC {} class C2 extends SubClass.spC {} //interface I1 extends SubClass.pI {} //interface I2 extends SubClass.spI {} // Not allowed in inner classes. // static { ... } void m() { SubClass lx = new SubClass(); x.pi = 1; x.spi = 2; sx.pi = 1; sx.spi = 2; lx.pi = 1; lx.spi = 2; int t = x.pm(); int y = x.spm(); int u = sx.pm(); int v = sx.spm(); int w = lx.pm(); int z = lx.spm(); int i = x.pi; int j = x.spi; int n = sx.pi; int m = sx.spi; int k = lx.pi; int l = lx.spi; SubClass.pC obj1; SubClass.spC obj2; SubClass.pI obj3; SubClass.spI obj4; Object o1 = (SubClass.pC) null; Object o2 = (SubClass.spC) null; Object o3 = (SubClass.pI) null; Object o4 = (SubClass.spI) null; class C1 extends SubClass.pC {} class C2 extends SubClass.spC {} //interface I1 extends SubClass.pI {} //interface I2 extends SubClass.spI {} } } }
12,840
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ProtectedAccess_2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedAccess_2.java
/* * Copyright (c) 1999, 2001, 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 4277524 * @summary Verify that static reference to protected member of unrelated class is disallowed. * @author maddox * * @run compile/fail ProtectedAccess_2.java */ public class ProtectedAccess_2 { public static void main(String[] args){ java.awt.Toolkit.getNativeContainer(null); } }
1,387
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ProtectedMemberAccess4.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess4.java
/* * @test /nodynamiccopyright/ * @bug 4319507 4785453 * @summary Verify correct implementation of JLS2e 6.6.2.1 * @author maddox * * @compile/fail/ref=ProtectedMemberAccess4.out -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess4.java */ // 33 errors expected. import pkg.SuperClass; class ProtectedMemberAccess4 extends pkg.SuperClass { // Access to a protected instance (non-static) field, instance method, // or member type by a qualified name is always legal in a subclass of // the class in which the member is declared. Such access to a protected // instance field or instance method is allowed only if the qualifying type // or the type of the qualifying expression is (a subclass of) the class // in which the reference occurs. In this test case, the qualifying type // is a superclass, thus all of the qualified references to instance fields // and instance methods are illegal. pkg.SuperClass x = new pkg.SuperClass(); static pkg.SuperClass sx = new pkg.SuperClass(); int i = x.pi; // illegal int j = x.spi; // ok int n = sx.pi; // illegal int m = sx.spi; // ok static int sn = sx.pi; // illegal static int sm = sx.spi; // ok int w = x.pm(); // illegal int y = x.spm(); // ok int u = sx.pm(); // illegal int v = sx.spm(); // ok pkg.SuperClass.pC obj1; // ok pkg.SuperClass.spC obj2; // ok pkg.SuperClass.pI obj3; // ok pkg.SuperClass.spI obj4; // ok Object o1 = (pkg.SuperClass.pC) null; // ok Object o2 = (pkg.SuperClass.spC) null; // ok Object o3 = (pkg.SuperClass.pI) null; // ok Object o4 = (pkg.SuperClass.spI) null; // ok class C1 extends pkg.SuperClass.pC {} // ok class C2 extends pkg.SuperClass.spC {} // ok interface I1 extends pkg.SuperClass.pI {} // ok interface I2 extends pkg.SuperClass.spI {} // ok static { pkg.SuperClass lx = new pkg.SuperClass(); sx.pi = 1; // illegal sx.spi = 2; // ok lx.pi = 1; // illegal lx.spi = 2; // ok int n = sx.pi; // illegal int m = sx.spi; // ok int k = lx.pi; // illegal int l = lx.spi; // ok int u = sx.pm(); // illegal int v = sx.spm(); // ok int w = lx.pm(); // illegal int z = lx.spm(); // ok pkg.SuperClass.pC obj1; // ok pkg.SuperClass.spC obj2; // ok pkg.SuperClass.pI obj3; // ok pkg.SuperClass.spI obj4; // ok Object o1 = (pkg.SuperClass.pC) null; // ok Object o2 = (pkg.SuperClass.spC) null; // ok Object o3 = (pkg.SuperClass.pI) null; // ok Object o4 = (pkg.SuperClass.spI) null; // ok //class C1 extends pkg.SuperClass.pC {} class C2 extends pkg.SuperClass.spC {} // ok //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } void m() { pkg.SuperClass lx = new pkg.SuperClass(); x.pi = 1; // illegal x.spi = 2; // ok sx.pi = 1; // illegal sx.spi = 2; // ok lx.pi = 1; // illegal lx.spi = 2; // ok int t = x.pm(); // illegal int y = x.spm(); // ok int u = sx.pm(); // illegal int v = sx.spm(); // ok int w = lx.pm(); // illegal int z = lx.spm(); // ok int i = x.pi; // illegal int j = x.spi; // ok int n = sx.pi; // illegal int m = sx.spi; // ok int k = lx.pi; // illegal int l = lx.spi; // ok pkg.SuperClass.pC obj1; // ok pkg.SuperClass.spC obj2; // ok pkg.SuperClass.pI obj3; // ok pkg.SuperClass.spI obj4; // ok Object o1 = (pkg.SuperClass.pC) null; // ok Object o2 = (pkg.SuperClass.spC) null; // ok Object o3 = (pkg.SuperClass.pI) null; // ok Object o4 = (pkg.SuperClass.spI) null; // ok class C1 extends pkg.SuperClass.pC {} // ok class C2 extends pkg.SuperClass.spC {} // ok //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } class Inner { int i = x.pi; // illegal int j = x.spi; // ok int n = sx.pi; // illegal int m = sx.spi; // ok //static int sn = sx.pi; //static int sm = sx.spi; int w = x.pm(); // illegal int y = x.spm(); // ok int u = sx.pm(); // illegal int v = sx.spm(); // ok pkg.SuperClass.pC obj1; // ok pkg.SuperClass.spC obj2; // ok pkg.SuperClass.pI obj3; // ok pkg.SuperClass.spI obj4; // ok Object o1 = (pkg.SuperClass.pC) null; // ok Object o2 = (pkg.SuperClass.spC) null; // ok Object o3 = (pkg.SuperClass.pI) null; // ok Object o4 = (pkg.SuperClass.spI) null; // ok class C1 extends pkg.SuperClass.pC {} // ok class C2 extends pkg.SuperClass.spC {} // ok //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} // Not allowed in inner classes. // static { ... } void m() { pkg.SuperClass lx = new pkg.SuperClass(); x.pi = 1; // illegal x.spi = 2; // ok sx.pi = 1; // illegal sx.spi = 2; // ok lx.pi = 1; // illegal lx.spi = 2; // ok int t = x.pm(); // illegal int y = x.spm(); // ok int u = sx.pm(); // illegal int v = sx.spm(); // ok int w = lx.pm(); // illegal int z = lx.spm(); // ok int i = x.pi; // illegal int j = x.spi; // ok int n = sx.pi; // illegal int m = sx.spi; // ok int k = lx.pi; // illegal int l = lx.spi; // ok pkg.SuperClass.pC obj1; // ok pkg.SuperClass.spC obj2; // ok pkg.SuperClass.pI obj3; // ok pkg.SuperClass.spI obj4; // ok Object o1 = (pkg.SuperClass.pC) null; // ok Object o2 = (pkg.SuperClass.spC) null; // ok Object o3 = (pkg.SuperClass.pI) null; // ok Object o4 = (pkg.SuperClass.spI) null; // ok class C1 extends pkg.SuperClass.pC {} // ok class C2 extends pkg.SuperClass.spC {} // ok //interface I1 extends pkg.SuperClass.pI {} //interface I2 extends pkg.SuperClass.spI {} } } }
8,363
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ProtectedAccess_1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedAccess_1.java
/* * Copyright (c) 1999, 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 4249096 * @summary Verify that special access checks for inherited protected members * are not applied to static members, per specification revision. * @author maddox * * @compile ProtectedAccess_1.java */ /* * Previously, javac handled the JLS 6.6.2 access check for * inherited static protected members differently when accessed * via a static reference or via an instance. * The current specification draft now drops all 6.6.2 checks * for static members. */ import p.SuperClass; class ProtectedAccess_1 extends SuperClass { { SuperClass.i = 5; // OK new SuperClass().i = 5; // OK } }
1,713
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
SuperClass.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/pkg/SuperClass.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 pkg; public class SuperClass { protected int pi; static protected int spi; protected int pm() { return 1; } static protected int spm() { return 1; } protected class pC { } static protected class spC { } protected interface pI { } static protected interface spI { } }
1,353
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
SuperClass.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/p/SuperClass.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. */ package p; public class SuperClass { protected static int i; }
1,119
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Main.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess5/Main.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 4786115 * @summary (cl) Odd IllegalAccessError across jar-file boundaries * @author gafter * * @compile z1/Z1.java z2/Z2.java * @run main z1.Z1 */ class Main { // this source file is not compiled for this test. }
1,296
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Z2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess5/z2/Z2.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. */ package z2; public class Z2 extends z1.Z1 { public static class T extends z1.Z1 { { Z2 z2 = new Z2(); z2.x = 3; } } }
1,219
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Z1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/protectedAccess/ProtectedMemberAccess5/z1/Z1.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. */ package z1; public class Z1 { protected int x; public static void main(String[] args) { new z2.Z2.T(); } }
1,180
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T5024091.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/T5024091/T5024091.java
/* * @test /nodynamiccopyright/ * @bug 5024091 * @summary AssertionError shouldn't be thrown * @author Wei Tao * @compile/fail/ref=T5024091.out -XDfailcomplete=java.lang.StringBuilder -XDdev -XDrawDiagnostics T5024091.java */ public class T5024091 { private final String[] stringArray = {"s", "t", "r"}; public void foo() { String str = "S = " + stringArray[0]; } }
399
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7142086.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/7142086/T7142086.java
/* * Copyright (c) 2012, 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 7142086 * @summary performance problem in Check.checkOverrideClashes(...) * @run main/timeout=10 T7142086 */ import com.sun.source.util.JavacTask; import java.net.URI; import java.util.List; import java.util.ArrayList; 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 T7142086 { final static int N_METHODS = 1000; static class TestClass extends SimpleJavaFileObject { String methTemplate = "abstract void m(A#N p);"; String classTemplate = "abstract class Test { #M }"; String source; public TestClass() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); StringBuilder buf = new StringBuilder(); for (int i = 0 ; i < N_METHODS ; i++) { buf.append(methTemplate.replace("#N", String.valueOf(i))); buf.append("\n"); } source = classTemplate.replace("#M", buf.toString()); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } static class AnSource extends SimpleJavaFileObject { String classTemplate = "abstract class A#N { }"; String source; public AnSource(int n) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = classTemplate.replace("#N", String.valueOf(n)); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } public static void main(String... args) throws Exception { ArrayList<JavaFileObject> sources = new ArrayList<>(); for (int i = 0 ; i < N_METHODS ; i++) { sources.add(new AnSource(i)); } sources.add(new TestClass()); new T7142086().run(sources); } void run(List<JavaFileObject> sources) throws Exception { DiagnosticChecker dc = new DiagnosticChecker(); JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, null, null, sources); ct.analyze(); } static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean errorFound; public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { throw new AssertionError("unexpected diagnostic: " + diagnostic.getMessage(Locale.getDefault())); } } } }
3,940
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
StringSwitches.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/StringSwitches.java
/* * Copyright (c) 2009, 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 6827009 7071246 * @summary Positive tests for strings in switch. * @author Joseph D. Darcy */ public class StringSwitches { public static void main(String... args) { int failures = 0; failures += testPileup(); failures += testSwitchingTwoWays(); failures += testNamedBreak(); failures += testExtraParens(); if (failures > 0) { throw new RuntimeException(); } } /* * A zero length string and all strings consisting only of the * zero character \u0000 have a hash code of zero. This method * maps such strings to the number of times \u0000 appears for 0 * through 6 occurrences. */ private static int zeroHashes(String s) { int result = Integer.MAX_VALUE; switch(s) { case "": return 0; case "\u0000": result = 1; break; case "\u0000\u0000": return 2; case "\u0000\u0000\u0000": result = 3; break; case "\u0000\u0000\u0000\u0000": return 4; case "\u0000\u0000\u0000\u0000\u0000": result = 5; break; case "\u0000\u0000\u0000\u0000\u0000\u0000": return 6; default: result = -1; } return result; } private static int testPileup() { int failures = 0; String zero = ""; for(int i = 0; i <= 6; i++, zero += "\u0000") { int result = zeroHashes(zero); if (result != i) { failures++; System.err.printf("For string \"%s\" unexpectedly got %d instead of %d%n.", zero, result, i); } } if (zeroHashes("foo") != -1) { failures++; System.err.println("Failed to get -1 for input string."); } return failures; } /** * Verify that a switch on an enum and a switch with the same * structure on the string name of an enum compute equivalent * values. */ private static int testSwitchingTwoWays() { int failures = 0; for(MetaSynVar msv : MetaSynVar.values()) { int enumResult = enumSwitch(msv); int stringResult = stringSwitch(msv.name()); if (enumResult != stringResult) { failures++; System.err.printf("One value %s, computed 0x%x with the enum switch " + "and 0x%x with the string one.%n", msv, enumResult, stringResult); } } return failures; } private static enum MetaSynVar { FOO, BAR, BAZ, QUX, QUUX, QUUUX, MUMBLE, FOOBAR; } private static int enumSwitch(MetaSynVar msv) { int result = 0; switch(msv) { case FOO: result |= (1<<0); // fallthrough: case BAR: case BAZ: result |= (1<<1); break; default: switch(msv) { case QUX: result |= (1<<2); break; case QUUX: result |= (1<<3); default: result |= (1<<4); } result |= (1<<5); break; case MUMBLE: result |= (1<<6); return result; case FOOBAR: result |= (1<<7); break; } result |= (1<<8); return result; } private static int stringSwitch(String msvName) { int result = 0; switch(msvName) { case "FOO": result |= (1<<0); // fallthrough: case "BAR": case "BAZ": result |= (1<<1); break; default: switch(msvName) { case "QUX": result |= (1<<2); break; case "QUUX": result |= (1<<3); default: result |= (1<<4); } result |= (1<<5); break; case "MUMBLE": result |= (1<<6); return result; case "FOOBAR": result |= (1<<7); break; } result |= (1<<8); return result; } private static int testNamedBreak() { int failures = 0; String[] testStrings = {"a", "b", "c", "d", "e"}; int[] testExpected = { 0b101011, 0b101, 0b100001, 0b101000, 0b10000}; for(int i = 0; i < testStrings.length; i++) { int expected = testExpected[i]; int result = namedBreak(testStrings[i]); if (result != expected) { failures++; System.err.printf("On input %s, got %d instead of %d.%n", testStrings[i], result, expected); } } return failures; } private static int namedBreak(String s) { int result = 0; outer: switch(s) { case "a": case "b": case "c": result |= (1<<0); inner: switch(s + s) { case "aa": result |= (1<<1); break inner; case "cc": break outer; default: result |= (1<<2); return result; } case "d": result |= (1<<3); break outer; default: return result |= (1<<4); } result |= (1<<5); return result; } private static int testExtraParens() { int failures = 1; String s = "first"; switch(s) { case (("first")): failures = 0; break; case ("second"): throw new RuntimeException("Should not be reached."); } return failures; } }
7,085
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
NonConstantLabel.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/NonConstantLabel.java
/* * @test /nodynamiccopyright/ * @bug 6827009 * @summary Check for non-constant case labels. * @compile/fail -source 6 NonConstantLabel.java * @compile/fail/ref=NonConstantLabel.out -XDrawDiagnostics NonConstantLabel.java */ class NonConstantLabel { String m(String s) { String fauxConstant = "Goodbye Cruel World"; switch(s) { case "Hello World": return(s); case fauxConstant: return (s + s); } } }
480
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadlyTypedLabel1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/BadlyTypedLabel1.java
/* * @test /nodynamiccopyright/ * @bug 6827009 * @summary Check for case labels of different types. * @compile/fail -source 6 BadlyTypedLabel1.java * @compile/fail/ref=BadlyTypedLabel1.out -XDrawDiagnostics BadlyTypedLabel1.java */ class BadlyTypedLabel1 { String m(String s) { switch(s) { case "Hello World": return(s); case 42: return ("Don't forget your towel!"); } } }
444
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadlyTypedLabel2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/BadlyTypedLabel2.java
/* * @test /nodynamiccopyright/ * @bug 6827009 * @summary Check for case lables of different types. * @compile/fail -source 6 BadlyTypedLabel2.java * @compile/fail/ref=BadlyTypedLabel2.out -XDrawDiagnostics BadlyTypedLabel2.java */ import static java.math.RoundingMode.*; class BadlyTypedLabel2 { String m(String s) { switch(s) { case "Oh what a feeling...": return(s); case CEILING: return ("... switching on the ceiling!"); } } }
504
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
RepeatedStringCaseLabels2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/RepeatedStringCaseLabels2.java
/* * @test /nodynamiccopyright/ * @bug 6827009 * @summary Check for repeated string case labels. * @compile/fail -source 6 RepeatedStringCaseLabels2.java * @compile/fail/ref=RSCL2.out -XDrawDiagnostics RepeatedStringCaseLabels2.java */ class RepeatedStringCaseLabels2 { String m(String s) { final String constant = "Hello" + " " + "World"; switch(s) { case "Hello World": return(s); case constant: return (s + s); } } }
499
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
RepeatedStringCaseLabels1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/RepeatedStringCaseLabels1.java
/* * @test /nodynamiccopyright/ * @bug 6827009 * @summary Check for repeated string case labels. * @compile/fail -source 6 RepeatedStringCaseLabels1.java * @compile/fail/ref=RSCL1.out -XDrawDiagnostics RepeatedStringCaseLabels1.java */ class RepeatedStringCaseLabels1 { String m(String s) { switch(s) { case "Hello World": return(s); case "Hello" + " " + "World": return (s + s); } } }
457
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
OneCaseSwitches.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/StringsInSwitch/OneCaseSwitches.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 6827009 * @summary Positive tests for strings in switch with few alternatives. * @compile/fail -source 6 OneCaseSwitches.java * @compile OneCaseSwitches.java * @run main OneCaseSwitches * @author Joseph D. Darcy */ import java.lang.reflect.*; import java.lang.annotation.*; import java.util.*; import static java.lang.annotation.RetentionPolicy.*; public class OneCaseSwitches { @Retention(RUNTIME) @interface TestMeForNull {} @TestMeForNull public static int zeroCasesNoDefault(String s, Set<String> stringSet, boolean expected) { int failures = 0; switch(s) { } return failures; } @TestMeForNull public static int zeroCasesWithDefault(String s, Set<String> stringSet, boolean expected) { int failures = 2; boolean addResult; switch(s) { default: failures = 0; addResult = stringSet.add(s); if (addResult != expected) { failures++; System.err.println("zeroCaseWithDefault: Expectedly got add result of " + addResult + " on string " + s); } } return failures; } @TestMeForNull public static int zeroCasesWithDefaultBreak(String s, Set<String> stringSet, boolean expected) { int failures = 2; boolean addResult; switch(s) { default: failures = zeroCasesWithDefault(s, stringSet, expected); break; } return failures; } @TestMeForNull public static int oneCaseNoDefault(String s, Set<String> stringSet, boolean expected) { int failures = 2; boolean addResult; switch(s) { case "foo": failures = 0; addResult = stringSet.add(s); if (addResult != expected) { failures++; System.err.println("oneCaseNoDefault: Unexpectedly got add result of " + addResult + " on string " + s); } } return failures; } @TestMeForNull public static int oneCaseNoDefaultBreak(String s, Set<String> stringSet, boolean expected) { int failures = 2; boolean addResult; switch(s) { case "foo": failures = oneCaseNoDefaultBreak(s, stringSet, expected); break; } return failures; } @TestMeForNull public static int oneCaseWithDefault(String s, Set<String> stringSet, boolean expected) { int failures = 2; boolean addResult;; switch(s) { case "foo": failures = 0; addResult = stringSet.add(s); if (addResult != expected) { failures++; System.err.println("oneCaseNoDefault: Expectedly got add result of " + addResult + " on string " + s); } break; default: break; } return failures; } @TestMeForNull public static int oneCaseBreakOnly(String s, Set<String> stringSet, boolean expected) { int failures = 1; switch(s) { case "foo": break; } failures = 0; return failures; } @TestMeForNull public static int oneCaseDefaultBreakOnly(String s, Set<String> stringSet, boolean expected) { int failures = 1; switch(s) { default: break; } failures = 0; return failures; } static int testNullBehavior() { int failures = 0; int count = 0; Method[] methods = OneCaseSwitches.class.getDeclaredMethods(); try { for(Method method : methods) { count++; try { if (method.isAnnotationPresent(TestMeForNull.class)) { System.out.println("Testing method " + method); method.invoke(null, (String)null, emptyStringSet, false); failures++; System.err.println("Didn't get NPE as expected from " + method); } } catch (InvocationTargetException ite) { // Expected Throwable targetException = ite.getTargetException(); if (! (targetException instanceof NullPointerException)) { failures++; // Wrong exception thrown System.err.println("Didn't get expected target exception NPE, got " + ite.getClass().getName()); } } } } catch (Exception e) { throw new RuntimeException(e); } if (count == 0) { failures++; System.err.println("Did not find any annotated methods."); } return failures; } static int testZeroCases() { int failures = 0; Set<String> noDefaultSet = new HashSet<String>(); Set<String> defaultSet = new HashSet<String>(); zeroCasesNoDefault(FOO, noDefaultSet, false); for(String word : words) { zeroCasesNoDefault(word, noDefaultSet, false); } if (!noDefaultSet.isEmpty()) { failures++; System.err.println("Non-empty set after zeroCasesNoDefault"); } for(String word : words) { zeroCasesWithDefault(word, defaultSet, true); } if (defaultSet.size() != words.length) { failures++; System.err.println("Missing strings after zeroCasesWithDefault"); } return failures; } static int testOneCaseNoDefault() { int failures = 0; Set<String> s = new HashSet<String>(); s.add("foo"); Set<String> fooSet = Collections.unmodifiableSet(s); Set<String> testSet = new HashSet<String>(); oneCaseNoDefault(FOO, testSet, true); if (!testSet.equals(fooSet)) { failures++; System.err.println("Unexpected result from oneCaseNoDefault: didn't get {\"Foo\"}"); } for(String word : words) { oneCaseNoDefault(word, testSet, false); } if (!testSet.equals(fooSet)) { failures++; System.err.println("Unexpected result from oneCaseNoDefault: didn't get {\"Foo\"}"); } return failures; } static int testBreakOnly() { int failures = 0; for(String word : words) { failures += oneCaseBreakOnly(word, emptyStringSet, true); failures += oneCaseDefaultBreakOnly(word, emptyStringSet, true); } return failures; } static int testExpressionEval() { String s = "a"; int errors = 2; System.out.println("Testing expression evaluation."); switch (s + s) { case "aa": errors = 0; break; case "aaaa": errors = 1; System.err.println("Suspected bad expression evaluation."); break; default: throw new RuntimeException("Should not reach here."); } return errors; } static final String FOO = "foo"; static final String[] words = {"baz", "quux", "wombat", "\u0ccc\u0012"}; // hash collision with "foo" final static Set<String> emptyStringSet = Collections.emptySet(); public static void main(String... args) { int failures = 0; failures += testNullBehavior(); failures += testZeroCases(); failures += testOneCaseNoDefault(); failures += testBreakOnly(); failures += testExpressionEval(); if (failures > 0) { throw new RuntimeException(); } } }
9,071
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrTests.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrTests.java
/* * Copyright (c) 2009, 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 6911256 6964740 * @summary Tests of generated TWR code. */ import java.util.List; import java.util.ArrayList; public class TwrTests { public static void main(String[] args) { testCreateFailure1(); testCreateFailure2(); testCreateFailure2Nested(); testCreateFailure3(); testCreateFailure3Nested(); testCreateFailure4(); testCreateFailure4Nested(); testCreateFailure5(); testCreateFailure5Nested(); testCreateSuccess1(); testCreateSuccess2(); testCreateSuccess2Nested(); testCreateSuccess3(); testCreateSuccess3Nested(); testCreateSuccess4(); testCreateSuccess4Nested(); testCreateSuccess5(); testCreateSuccess5Nested(); } /* * The following tests simulate a creation failure of every possible * resource in an TWR block, and check to make sure that the failure * prevents creation of subsequent resources, and that all created * resources are properly closed, even if one or more of the close * attempts fails. */ public static void testCreateFailure1() { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(0); try (Resource r0 = createResource(0, 0, 0, closedList)) { throw new AssertionError("Resource creation succeeded"); } catch (Resource.CreateFailException e) { creationFailuresDetected++; if (e.resourceId() != 0) { throw new AssertionError("Wrong resource creation " + e.resourceId() + " failed"); } } catch (Resource.CloseFailException e) { throw new AssertionError("Unexpected CloseFailException: " + e.resourceId()); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, 0); } public static void testCreateFailure2() { for (int createFailureId = 0; createFailureId < 2; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList); Resource r1 = createResource(1, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed"); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure2Nested() { for (int createFailureId = 0; createFailureId < 2; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList)) { try(Resource r1 = createResource(1, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed"); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure3() { for (int createFailureId = 0; createFailureId < 3; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList); Resource r1 = createResource(1, createFailureId, bitMap, closedList); Resource r2 = createResource(2, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure3Nested() { for (int createFailureId = 0; createFailureId < 3; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList)) { try (Resource r1 = createResource(1, createFailureId, bitMap, closedList)) { try (Resource r2 = createResource(2, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } } } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure4() { for (int createFailureId = 0; createFailureId < 4; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList); Resource r1 = createResource(1, createFailureId, bitMap, closedList); Resource r2 = createResource(2, createFailureId, bitMap, closedList); Resource r3 = createResource(3, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure4Nested() { for (int createFailureId = 0; createFailureId < 4; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList)) { try (Resource r1 = createResource(1, createFailureId, bitMap, closedList)) { try (Resource r2 = createResource(2, createFailureId, bitMap, closedList)) { try (Resource r3 = createResource(3, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } } } } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure5() { for (int createFailureId = 0; createFailureId < 5; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList); Resource r1 = createResource(1, createFailureId, bitMap, closedList); Resource r2 = createResource(2, createFailureId, bitMap, closedList); Resource r3 = createResource(3, createFailureId, bitMap, closedList); Resource r4 = createResource(4, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } public static void testCreateFailure5Nested() { for (int createFailureId = 0; createFailureId < 5; createFailureId++) { for (int bitMap = 0, n = 1 << createFailureId; bitMap < n; bitMap++) { int creationFailuresDetected = 0; List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, createFailureId, bitMap, closedList)) { try (Resource r1 = createResource(1, createFailureId, bitMap, closedList)) { try (Resource r2 = createResource(2, createFailureId, bitMap, closedList)) { try (Resource r3 = createResource(3, createFailureId, bitMap, closedList)) { try (Resource r4 = createResource(4, createFailureId, bitMap, closedList)) { throw new AssertionError("Entire resource creation succeeded"); } } } } } catch (Resource.CreateFailException e) { creationFailuresDetected++; checkCreateFailureId(e.resourceId(), createFailureId); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { throw new AssertionError("Secondary exception suppression failed:" + e); } checkForSingleCreationFailure(creationFailuresDetected); checkClosedList(closedList, createFailureId); } } } /** * Create a resource with the specified ID. The ID must be less than createFailureId. * A subsequent attempt to close the resource will fail iff the corresponding bit * is set in closeFailureBitMap. When an attempt is made to close this resource, * its ID will be added to closedList, regardless of whether the attempt succeeds. * * @param id the ID of this resource * @param createFailureId the ID of the resource whose creation will fail * @param closeFailureBitMap a bit vector describing which resources should throw an * exception when close is attempted * @param closedList a list on which to record resource close attempts * @throws AssertionError if no attempt should be made to create this resource */ private static Resource createResource(int id, int createFailureId, int closeFailureBitMap, List<Integer> closedList) throws Resource.CreateFailException { if (id > createFailureId) throw new AssertionError("Resource " + id + " shouldn't be created"); boolean createSucceeds = id != createFailureId; boolean closeSucceeds = (closeFailureBitMap & (1 << id)) == 0; return new Resource(id, createSucceeds, closeSucceeds, closedList); } /** * Check that an observed creation failure has the expected resource ID. * * @param foundId the ID of the resource whose creation failed * @param expectedId the ID of the resource whose creation should have failed */ private static void checkCreateFailureId(int foundId, int expectedId) { if (foundId != expectedId) throw new AssertionError("Wrong resource creation failed. Found ID " + foundId + " expected " + expectedId); } /** * Check for proper suppressed exceptions in proper order. * * @param suppressedExceptions the suppressed exceptions array returned by * getSuppressed() * @bitmap a bitmap indicating which suppressed exceptions are expected. * Bit i is set iff id should throw a CloseFailException. */ private static void checkSuppressedExceptions(Throwable[] suppressedExceptions, int bitMap) { if (suppressedExceptions.length != Integer.bitCount(bitMap)) throw new AssertionError("Expected " + Integer.bitCount(bitMap) + " suppressed exceptions, got " + suppressedExceptions.length); int prevCloseFailExceptionId = Integer.MAX_VALUE; for (Throwable t : suppressedExceptions) { int id = ((Resource.CloseFailException) t).resourceId(); if ((1 << id & bitMap) == 0) throw new AssertionError("Unexpected suppressed CloseFailException: " + id); if (id > prevCloseFailExceptionId) throw new AssertionError("Suppressed CloseFailException" + id + " followed " + prevCloseFailExceptionId); } } /** * Check that exactly one resource creation failed. * * @param numCreationFailuresDetected the number of creation failures detected */ private static void checkForSingleCreationFailure(int numCreationFailuresDetected) { if (numCreationFailuresDetected != 1) throw new AssertionError("Wrong number of creation failures: " + numCreationFailuresDetected); } /** * Check that a close was attempted on every resourced that was successfully opened, * and that the close attempts occurred in the proper order. * * @param closedList the resource IDs of the close attempts, in the order they occurred * @param the ID of the resource whose creation failed. Close attempts should occur * for all previous resources, in reverse order. */ private static void checkClosedList(List<Integer> closedList, int createFailureId) { List<Integer> expectedList = new ArrayList<Integer>(createFailureId); for (int i = createFailureId - 1; i >= 0; i--) expectedList.add(i); if (!closedList.equals(expectedList)) throw new AssertionError("Closing sequence " + closedList + " != " + expectedList); } /* * The following tests simulate the creation of several resources, followed * by success or failure of forward processing. They test that all resources * are properly closed, even if one or more of the close attempts fails. */ public static void testCreateSuccess1() { for (int bitMap = 0, n = 1 << 1; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 1); } } } public static void testCreateSuccess2() { for (int bitMap = 0, n = 1 << 2; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList); Resource r1 = createResource(1, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 2); } } } public static void testCreateSuccess2Nested() { for (int bitMap = 0, n = 1 << 2; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList)) { try (Resource r1 = createResource(1, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 2); } } } public static void testCreateSuccess3() { for (int bitMap = 0, n = 1 << 3; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList); Resource r1 = createResource(1, bitMap, closedList); Resource r2 = createResource(2, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 3); } } } public static void testCreateSuccess3Nested() { for (int bitMap = 0, n = 1 << 3; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList)) { try (Resource r1 = createResource(1, bitMap, closedList)) { try (Resource r2 = createResource(2, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } } } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 3); } } } public static void testCreateSuccess4() { for (int bitMap = 0, n = 1 << 4; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList); Resource r1 = createResource(1, bitMap, closedList); Resource r2 = createResource(2, bitMap, closedList); Resource r3 = createResource(3, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 4); } } } public static void testCreateSuccess4Nested() { for (int bitMap = 0, n = 1 << 4; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList)) { try (Resource r1 = createResource(1, bitMap, closedList)) { try (Resource r2 = createResource(2, bitMap, closedList)) { try (Resource r3 = createResource(3, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } } } } catch (Resource.CreateFailException e) { throw new AssertionError( "Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 4); } } } public static void testCreateSuccess5() { for (int bitMap = 0, n = 1 << 5; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList); Resource r1 = createResource(1, bitMap, closedList); Resource r2 = createResource(2, bitMap, closedList); Resource r3 = createResource(3, bitMap, closedList); Resource r4 = createResource(4, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } catch (Resource.CreateFailException e) { throw new AssertionError("Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 5); } } } public static void testCreateSuccess5Nested() { for (int bitMap = 0, n = 1 << 5; bitMap < n; bitMap++) { for (int failure = 0; failure < 2; failure++) { List<Integer> closedList = new ArrayList<Integer>(); try (Resource r0 = createResource(0, bitMap, closedList)) { try (Resource r1 = createResource(1, bitMap, closedList)) { try (Resource r2 = createResource(2, bitMap, closedList)) { try (Resource r3 = createResource(3, bitMap, closedList)) { try (Resource r4 = createResource(4, bitMap, closedList)) { if (failure != 0) throw new MyKindOfException(); } } } } } catch (Resource.CreateFailException e) { throw new AssertionError("Resource creation failed: " + e.resourceId()); } catch (MyKindOfException e) { if (failure == 0) throw new AssertionError("Unexpected MyKindOfException"); checkSuppressedExceptions(e.getSuppressed(), bitMap); } catch (Resource.CloseFailException e) { if (failure == 1) throw new AssertionError("Secondary exception suppression failed"); int id = e.resourceId(); if (bitMap == 0) throw new AssertionError("Unexpected CloseFailException: " + id); int highestCloseFailBit = Integer.highestOneBit(bitMap); if (1 << id != highestCloseFailBit) { throw new AssertionError("CloseFailException: got id " + id + ", expected lg(" + highestCloseFailBit +")"); } checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit); } checkClosedList(closedList, 5); } } } private static Resource createResource(int id, int closeFailureBitMap, List<Integer> closedList) throws Resource.CreateFailException { boolean closeSucceeds = (closeFailureBitMap & (1 << id)) == 0; return new Resource(id, true, closeSucceeds, closedList); } private static class MyKindOfException extends Exception { } } class Resource implements AutoCloseable { /** A number identifying this resource */ private final int resourceId; /** Whether the close call on this resource should succeed or fail */ private final boolean closeSucceeds; /** When resource is closed, it records its ID in this list */ private final List<Integer> closedList; Resource(int resourceId, boolean createSucceeds, boolean closeSucceeds, List<Integer> closedList) throws CreateFailException { if (!createSucceeds) throw new CreateFailException(resourceId); this.resourceId = resourceId; this.closeSucceeds = closeSucceeds; this.closedList = closedList; } public void close() throws CloseFailException { closedList.add(resourceId); if (!closeSucceeds) throw new CloseFailException(resourceId); } public static class ResourceException extends RuntimeException { private final int resourceId; public ResourceException(int resourceId) { super("Resource ID = " + resourceId); this.resourceId = resourceId; } public int resourceId() { return resourceId; } } public static class CreateFailException extends ResourceException { public CreateFailException(int resourceId) { super(resourceId); } } public static class CloseFailException extends ResourceException { public CloseFailException(int resourceId) { super(resourceId); } } }
38,231
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ResourceInterface.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/ResourceInterface.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 6970833 * @author Maurizio Cimadamore * @summary Try-with-resource implementation throws an NPE during Flow analysis * @compile/fail/ref=ResourceInterface.out -XDrawDiagnostics ResourceInterface.java */ class ResourceInterface { public void test1() { try(Resource1 r1 = null) { } } public void test2() { try(Resource2 r2 = null) { } } static class E1 extends Exception {} static class E2 extends Exception {} interface C1 extends AutoCloseable { void close() throws E1; } interface C2 extends AutoCloseable { void close() throws E2; } interface C3 extends AutoCloseable { void close() throws E2, E1; } static interface Resource1 extends C1, C2 {} static interface Resource2 extends C1, C3 {} }
1,873
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrOnNonResource.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrOnNonResource.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 7013420 * @author Joseph D. Darcy * @summary Verify invalid TWR block is not accepted. * @compile/fail -source 6 TwrOnNonResource.java * @compile/fail/ref=TwrOnNonResource.out -XDrawDiagnostics TwrOnNonResource.java */ class TwrOnNonResource { public static void main(String... args) { try(TwrOnNonResource aonr = new TwrOnNonResource()) { System.out.println(aonr.toString()); } try(TwrOnNonResource aonr = new TwrOnNonResource()) { System.out.println(aonr.toString()); } finally {;} try(TwrOnNonResource aonr = new TwrOnNonResource()) { System.out.println(aonr.toString()); } catch (Exception e) {;} } /* * A close method, but the class is <em>not</em> Closeable or * AutoCloseable. */ public void close() { throw new AssertionError("I'm not Closable!"); } }
952
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7022711.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/T7022711.java
/* * @test /nodynamiccopyright/ * @bug 7022711 * @summary compiler crash in try-with-resources * @compile/fail/ref=T7022711.out -XDrawDiagnostics T7022711.java */ import java.io.*; class T7022711 { public static void main (String args[]) throws Exception { try (DataInputStream is = new DataInputStream(new FileInputStream("x"))) { while (true) { is.getChar(); // method not found } } catch (EOFException e) { } } }
497
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7032633.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/T7032633.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 7032633 * @summary javac -Xlint:all warns about flush() within try on an auto-closeable resource * @compile -Xlint:try -Werror T7032633.java */ import java.io.IOException; import java.io.OutputStream; public class T7032633 { void test() throws IOException { try (OutputStream out = System.out) { out.flush(); } } }
1,428
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
DuplicateResource.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/DuplicateResource.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 6911256 6964740 6965277 7013420 * @author Maurizio Cimadamore * @summary Check that lowered try-with-resources block does not end up creating resource twice */ import java.util.ArrayList; public class DuplicateResource { static class TestResource implements AutoCloseable { TestResource() { resources.add(this); } boolean isClosed = false; public void close() throws Exception { isClosed = true; } } static ArrayList<TestResource> resources = new ArrayList<TestResource>(); public static void main(String[] args) { try(TestResource tr = new TestResource()) { //do something } catch (Exception e) { throw new AssertionError("Shouldn't reach here", e); } check(); } public static void check() { if (resources.size() != 1) { throw new AssertionError("Expected one resource, found: " + resources.size()); } TestResource resource = resources.get(0); if (!resource.isClosed) { throw new AssertionError("Resource used in try-with-resources block has not been automatically closed"); } } }
2,273
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
WeirdTwr.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/WeirdTwr.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 6911256 6964740 * @author Joseph D. Darcy * @summary Strange TWRs * @compile/fail -source 6 WeirdTwr.java * @compile WeirdTwr.java * @run main WeirdTwr */ public class WeirdTwr implements AutoCloseable { private static int closeCount = 0; public static void main(String... args) { try(WeirdTwr r1 = new WeirdTwr(); WeirdTwr r2 = r1) { if (r1 != r2) throw new RuntimeException("Unexpected inequality."); } if (closeCount != 2) throw new RuntimeException("bad closeCount" + closeCount); } public void close() { closeCount++; } }
1,699
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ExplicitFinal.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/ExplicitFinal.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 7013420 * @author Joseph D. Darcy * @summary Test that resource variables are accepted as explicitly final. */ import java.io.IOException; public class ExplicitFinal implements AutoCloseable { public static void main(String... args) { try(final ExplicitFinal r2 = new ExplicitFinal()) { r2.toString(); } catch (IOException ioe) { throw new AssertionError("Shouldn't reach here", ioe); } try(final @SuppressWarnings("unchecked") ExplicitFinal r3 = new ExplicitFinal()) { r3.toString(); } catch (IOException ioe) { throw new AssertionError("Shouldn't reach here", ioe); } try(@SuppressWarnings("unchecked") ExplicitFinal r4 = new ExplicitFinal()) { r4.toString(); } catch (IOException ioe) { throw new AssertionError("Shouldn't reach here", ioe); } } public void close() throws IOException { System.out.println("Calling close on " + this); } }
2,089
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
PlainTry.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/PlainTry.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 * @author Joseph D. Darcy * @summary Test error messages for an unadorned try * @compile/fail/ref=PlainTry6.out -XDrawDiagnostics -source 6 -Xlint:-options PlainTry.java * @compile/fail/ref=PlainTry.out -XDrawDiagnostics PlainTry.java */ public class PlainTry { public static void main(String... args) { try { ; } } }
444
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ResourceTypeVar.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/ResourceTypeVar.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 6911256 6964740 6965277 * @author Maurizio Cimadamore * @summary Resource of a type-variable type crashes Flow * @compile ResourceTypeVar.java */ class ResourceTypeVar<X extends AutoCloseable> { public void test() { try(X armflow = getX()) { //do something } catch (Exception e) { // Not reachable throw new AssertionError("Shouldn't reach here", e); } } X getX() { return null; } }
1,522
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadTwr.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/BadTwr.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 * @author Joseph D. Darcy * @summary Verify bad TWRs don't compile * @compile/fail -source 6 TwrFlow.java * @compile/fail/ref=BadTwr.out -XDrawDiagnostics BadTwr.java */ public class BadTwr implements AutoCloseable { public static void main(String... args) { // illegal repeated name try(BadTwr r1 = new BadTwr(); BadTwr r1 = new BadTwr()) { System.out.println(r1.toString()); } // illegal duplicate name of method argument try(BadTwr args = new BadTwr()) { System.out.println(args.toString()); final BadTwr thatsIt = new BadTwr(); thatsIt = null; } try(BadTwr name = new BadTwr()) { // illegal duplicate name of enclosing try try(BadTwr name = new BadTwr()) { System.out.println(name.toString()); } } } public void close() { ; } }
988
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BadTwrSyntax.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/BadTwrSyntax.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 * @author Joseph D. Darcy * @summary Verify bad TWRs don't compile * @compile/fail -source 6 BadTwrSyntax.java * @compile/fail/ref=BadTwrSyntax.out -XDrawDiagnostics BadTwrSyntax.java */ import java.io.IOException; public class BadTwrSyntax implements AutoCloseable { public static void main(String... args) throws Exception { // illegal double semicolon ending resources try(BadTwr twrflow = new BadTwr();;) { System.out.println(twrflow.toString()); } // but one semicolon is fine try(BadTwr twrflow = new BadTwr();) { System.out.println(twrflow.toString()); } } public void close() { ; } }
754
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ImplicitFinal.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/ImplicitFinal.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 6965277 7013420 * @author Maurizio Cimadamore * @summary Test that resource variables are implicitly final * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java */ import java.io.IOException; class ImplicitFinal implements AutoCloseable { public static void main(String... args) { try(ImplicitFinal r = new ImplicitFinal()) { r = null; //disallowed } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) { r1 = null; //disallowed } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } try(final ImplicitFinal r2 = new ImplicitFinal()) { r2 = null; //disallowed } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) { r3 = null; //disallowed } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } } public void close() throws IOException { throw new IOException(); } }
1,417
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
DuplicateResourceDecl.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 6965277 * @author Maurizio Cimadamore * @summary Check that resource variable is not accessible from catch/finally clause * @compile/fail/ref=DuplicateResourceDecl.out -XDrawDiagnostics DuplicateResourceDecl.java */ class DuplicateResourceDecl { public static void main(String[] args) { try(MyResource c = new MyResource();MyResource c = new MyResource()) { //do something } catch (Exception e) { } } static class MyResource implements AutoCloseable { public void close() throws Exception {} } }
609
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrFlow.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrFlow.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 7013420 * @author Joseph D. Darcy * @summary Test exception analysis of try-with-resources blocks * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java */ import java.io.IOException; public class TwrFlow implements AutoCloseable { public static void main(String... args) { try(TwrFlow twrFlow = new TwrFlow()) { System.out.println(twrFlow.toString()); } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } // CustomCloseException should be caught or added to throws clause } /* * A close method, but the class is <em>not</em> Closeable or * AutoCloseable. */ public void close() throws CustomCloseException { throw new CustomCloseException(); } } class CustomCloseException extends Exception {}
916
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ResourceOutsideTry.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/ResourceOutsideTry.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 6965277 * @author Maurizio Cimadamore * @summary Check that resource variable is not accessible from catch/finally clause * @compile/fail/ref=ResourceOutsideTry.out -XDrawDiagnostics ResourceOutsideTry.java */ class ResourceOutsideTry { void test() { try(MyResource c = new MyResource()) { //do something } catch (Exception e) { c.test(); } finally { c.test(); } } static class MyResource implements AutoCloseable { public void close() throws Exception {} void test() {} } }
634
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrLint.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrLint.java
/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 6965277 6967065 * @author Joseph D. Darcy * @summary Check that -Xlint:twr warnings are generated as expected * @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java */ class TwrLint implements AutoCloseable { private static void test1() { try(TwrLint r1 = new TwrLint(); TwrLint r2 = new TwrLint(); TwrLint r3 = new TwrLint()) { r1.close(); // The resource's close r2.close(42); // *Not* the resource's close // r3 not referenced } } @SuppressWarnings("try") private static void test2() { try(@SuppressWarnings("deprecation") AutoCloseable r4 = new DeprecatedAutoCloseable()) { // r4 not referenced - but no warning is generated because of @SuppressWarnings } catch(Exception e) { ; } } /** * The AutoCloseable method of a resource. */ @Override public void close () { return; } /** * <em>Not</em> the AutoCloseable method of a resource. */ public void close (int arg) { return; } } @Deprecated class DeprecatedAutoCloseable implements AutoCloseable { public DeprecatedAutoCloseable(){super();} @Override public void close () { return; } }
1,381
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
UnusedResourcesTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/UnusedResourcesTest.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 7023233 * @summary False positive for -Xlint:try with nested try with resources blocks */ import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.ClientCodeWrapper; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.JCDiagnostic; import java.net.URI; import java.util.Arrays; 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 UnusedResourcesTest { enum XlintOption { NONE("none"), TRY("try"); String opt; XlintOption(String opt) { this.opt = opt; } String getXlintOption() { return "-Xlint:" + opt; } } enum TwrStmt { TWR1("res1"), TWR2("res2"), TWR3("res3"); final String resourceName; private TwrStmt(String resourceName) { this.resourceName = resourceName; } } enum SuppressLevel { NONE, SUPPRESS; String getSuppressAnno() { return this == SUPPRESS ? "@SuppressWarnings(\"try\")" : ""; } } enum ResourceUsage { NONE(null), USE_R1(TwrStmt.TWR1), USE_R2(TwrStmt.TWR2), USE_R3(TwrStmt.TWR3); TwrStmt stmt; private ResourceUsage(TwrStmt stmt) { this.stmt = stmt; } String usedResourceName() { return stmt != null ? stmt.resourceName : null; } boolean isUsedIn(TwrStmt res, TwrStmt stmt) { return this.stmt == res && stmt.ordinal() >= this.stmt.ordinal(); } String getUsage(TwrStmt stmt) { return this != NONE && stmt.ordinal() >= this.stmt.ordinal() ? "use(" + usedResourceName() + ");" : ""; } } static class JavaSource extends SimpleJavaFileObject { String template = "class Resource implements AutoCloseable {\n" + "public void close() {}\n" + "}\n" + "class Test {\n" + "void use(Resource r) {}\n" + "#S void test() {\n" + "try (Resource #R1 = new Resource()) {\n" + "#U1_R1\n" + "#U1_R2\n" + "#U1_R3\n" + "try (Resource #R2 = new Resource()) {\n" + "#U2_R1\n" + "#U2_R2\n" + "#U2_R3\n" + "try (Resource #R3 = new Resource()) {\n" + "#U3_R1\n" + "#U3_R2\n" + "#U3_R3\n" + "}\n" + "}\n" + "}\n" + "}\n" + "}\n"; String source; public JavaSource(SuppressLevel suppressLevel, ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = template.replace("#S", suppressLevel.getSuppressAnno()). replace("#R1", TwrStmt.TWR1.resourceName). replace("#R2", TwrStmt.TWR2.resourceName). replace("#R3", TwrStmt.TWR3.resourceName). replace("#U1_R1", usage1.getUsage(TwrStmt.TWR1)). replace("#U1_R2", usage2.getUsage(TwrStmt.TWR1)). replace("#U1_R3", usage3.getUsage(TwrStmt.TWR1)). replace("#U2_R1", usage1.getUsage(TwrStmt.TWR2)). replace("#U2_R2", usage2.getUsage(TwrStmt.TWR2)). replace("#U2_R3", usage3.getUsage(TwrStmt.TWR2)). replace("#U3_R1", usage1.getUsage(TwrStmt.TWR3)). replace("#U3_R2", usage2.getUsage(TwrStmt.TWR3)). replace("#U3_R3", usage3.getUsage(TwrStmt.TWR3)); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } public static void main(String... args) throws Exception { for (XlintOption xlint : XlintOption.values()) { for (SuppressLevel suppressLevel : SuppressLevel.values()) { for (ResourceUsage usage1 : ResourceUsage.values()) { for (ResourceUsage usage2 : ResourceUsage.values()) { for (ResourceUsage usage3 : ResourceUsage.values()) { test(xlint, suppressLevel, usage1, usage2, usage3); } } } } } } // 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(XlintOption xlint, SuppressLevel suppressLevel, ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3) throws Exception { final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaSource source = new JavaSource(suppressLevel, usage1, usage2, usage3); DiagnosticChecker dc = new DiagnosticChecker(); JavacTask ct = (JavacTask)tool.getTask(null, fm, dc, Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source)); ct.analyze(); check(source, xlint, suppressLevel, usage1, usage2, usage3, dc); } static void check(JavaSource source, XlintOption xlint, SuppressLevel suppressLevel, ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3, DiagnosticChecker dc) { ResourceUsage[] usages = { usage1, usage2, usage3 }; boolean[] unusedFound = { dc.unused_r1, dc.unused_r2, dc.unused_r3 }; boolean[] usedResources = { false, false, false }; for (TwrStmt res : TwrStmt.values()) { outer: for (TwrStmt stmt : TwrStmt.values()) { for (ResourceUsage usage : usages) { if (usage.isUsedIn(res, stmt)) { usedResources[res.ordinal()] = true; break outer; } } } } for (TwrStmt stmt : TwrStmt.values()) { boolean unused = !usedResources[stmt.ordinal()] && xlint == XlintOption.TRY && suppressLevel != SuppressLevel.SUPPRESS; if (unused != unusedFound[stmt.ordinal()]) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nOptions: " + xlint.getXlintOption() + "\nFound unused res1: " + unusedFound[0] + "\nFound unused res2: " + unusedFound[1] + "\nFound unused res3: " + unusedFound[2] + "\nExpected unused res1: " + !usedResources[0] + "\nExpected unused res2: " + !usedResources[1] + "\nExpected unused res3: " + !usedResources[2]); } } } static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean unused_r1 = false; boolean unused_r2 = false; boolean unused_r3 = false; public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.WARNING && diagnostic.getCode().contains("try.resource.not.referenced")) { String varName = unwrap(diagnostic).getArgs()[0].toString(); if (varName.equals(TwrStmt.TWR1.resourceName)) { unused_r1 = true; } else if (varName.equals(TwrStmt.TWR2.resourceName)) { unused_r2 = true; } else if (varName.equals(TwrStmt.TWR3.resourceName)) { unused_r3 = true; } } } private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic instanceof JCDiagnostic) return (JCDiagnostic) diagnostic; if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper) return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d; throw new IllegalArgumentException(); } } }
10,162
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrSuppression.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrSuppression.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 6971877 * @author Joseph D. Darcy * @summary Verify a primary exception suppresses all throwables */ public class TwrSuppression implements AutoCloseable { public static void main(String... args) throws Throwable { try { try (TwrSuppression r1 = new TwrSuppression(false); TwrSuppression r2 = new TwrSuppression(true)) { throw new RuntimeException(); } } catch(RuntimeException e) { Throwable[] suppressedExceptions = e.getSuppressed(); int length = suppressedExceptions.length; if (length != 2) throw new RuntimeException("Unexpected length " + length); if (suppressedExceptions[0].getClass() != Error.class || suppressedExceptions[1].getClass() != Exception.class) { System.err.println("Unexpected suppressed types!"); e.printStackTrace(); throw new RuntimeException(e); } } } private boolean throwError; private TwrSuppression(boolean throwError) { this.throwError = throwError; } @Override public void close() throws Exception { if (throwError) { throw new Error(); } else { throw new Exception(); } } }
2,397
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrNullTests.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrNullTests.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 7020047 * @summary Test null handling of try-with-resources statement */ public class TwrNullTests { /* * Each try-with-resources statement generates two calls to the * close method for each resource: one for when there is a primary * exception present and the second for when a primary exception * is absent. The null handling of both cases needs to be * checked. */ public static void main(String... args) { testNormalCompletion(); testNoSuppression(); } /* * Verify empty try-with-resources on a null resource completes * normally; no NPE from the generated close call. */ private static void testNormalCompletion() { try(AutoCloseable resource = null) { return; // Nothing to see here, move along. } catch (Exception e) { throw new AssertionError("Should not be reached", e); } } /* * Verify that a NPE on a null resource is <em>not</em> added as a * suppressed exception to an exception from try block. */ private static void testNoSuppression() { try(AutoCloseable resource = null) { throw new java.io.IOException(); } catch(java.io.IOException ioe) { Throwable[] suppressed = ioe.getSuppressed(); if (suppressed.length != 0) { throw new AssertionError("Non-empty suppressed exceptions", ioe); } } catch (Exception e) { throw new AssertionError("Should not be reached", e); } } }
2,673
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
TwrMultiCatch.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/TwrMultiCatch.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 6911256 6964740 7013420 * @author Joseph D. Darcy * @summary Test that TWR and multi-catch play well together * @compile TwrMultiCatch.java * @run main TwrMultiCatch */ import java.io.IOException; public class TwrMultiCatch implements AutoCloseable { private final Class<? extends Exception> exceptionClass; private TwrMultiCatch(Class<? extends Exception> exceptionClass) { this.exceptionClass = exceptionClass; } public static void main(String... args) { test(new TwrMultiCatch(CustomCloseException1.class), CustomCloseException1.class); test(new TwrMultiCatch(CustomCloseException2.class), CustomCloseException2.class); } private static void test(TwrMultiCatch twrMultiCatch, Class<? extends Exception> expected) { try(TwrMultiCatch tmc = twrMultiCatch) { System.out.println(tmc.toString()); } catch (CustomCloseException1 | CustomCloseException2 exception) { if (!exception.getClass().equals(expected) ) { throw new RuntimeException("Unexpected catch!"); } } } public void close() throws CustomCloseException1, CustomCloseException2 { Throwable t; try { t = exceptionClass.newInstance(); } catch(ReflectiveOperationException rfe) { throw new RuntimeException(rfe); } try { throw t; } catch (CustomCloseException1 | CustomCloseException2 exception) { throw exception; } catch (Throwable throwable) { throw new RuntimeException(throwable); } } } class CustomCloseException1 extends Exception {} class CustomCloseException2 extends Exception {}
2,879
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
InterruptedExceptionTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.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 7027157 * @summary Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException */ import com.sun.source.util.JavacTask; import java.net.URI; import java.util.Arrays; 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 InterruptedExceptionTest { enum XlintOption { NONE("none"), TRY("try"); String opt; XlintOption(String opt) { this.opt = opt; } String getXlintOption() { return "-Xlint:" + opt; } } enum SuppressLevel { NONE, SUPPRESS; String getSuppressAnno() { return this == SUPPRESS ? "@SuppressWarnings(\"try\")" : ""; } } enum ClassKind { ABSTRACT_CLASS("abstract class", "implements", false), CLASS("class", "implements", true), INTERFACE("interface", "extends", false); String kindName; String extendsClause; boolean hasBody; private ClassKind(String kindName, String extendsClause, boolean hasBody) { this.kindName = kindName; this.extendsClause = extendsClause; this.hasBody = hasBody; } String getBody() { return hasBody ? "{}" : ";"; } } enum ExceptionKind { NONE("", false), EXCEPTION("Exception", true), INTERRUPTED_EXCEPTION("InterruptedException", true), ILLEGAL_ARGUMENT_EXCEPTION("IllegalArgumentException", false), X("X", false); String exName; boolean shouldWarn; private ExceptionKind(String exName, boolean shouldWarn) { this.exName = exName; this.shouldWarn = shouldWarn; } String getThrowsClause() { return this == NONE ? "" : "throws " + exName; } String getTypeArguments(ExceptionKind decl) { return (decl != X || this == NONE) ? "" : "<" + exName + ">"; } String getTypeParameter() { return this == X ? "<X extends Exception>" : ""; } } public static void main(String... args) throws Exception { //create default shared JavaCompiler - reused across multiple compilations JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); for (XlintOption xlint : XlintOption.values()) { for (SuppressLevel suppress_decl : SuppressLevel.values()) { for (SuppressLevel suppress_use : SuppressLevel.values()) { for (ClassKind ck : ClassKind.values()) { for (ExceptionKind ek_decl : ExceptionKind.values()) { for (ExceptionKind ek_use : ExceptionKind.values()) { new InterruptedExceptionTest(xlint, suppress_decl, suppress_use, ck, ek_decl, ek_use).run(comp, fm); } } } } } } } XlintOption xlint; SuppressLevel suppress_decl; SuppressLevel suppress_use; ClassKind ck; ExceptionKind ek_decl; ExceptionKind ek_use; JavaSource source; DiagnosticChecker diagChecker; InterruptedExceptionTest(XlintOption xlint, SuppressLevel suppress_decl, SuppressLevel suppress_use, ClassKind ck, ExceptionKind ek_decl, ExceptionKind ek_use) { this.xlint = xlint; this.suppress_decl = suppress_decl; this.suppress_use = suppress_use; this.ck = ck; this.ek_decl = ek_decl; this.ek_use = ek_use; this.source = new JavaSource(); this.diagChecker = new DiagnosticChecker(); } class JavaSource extends SimpleJavaFileObject { String template = "#S1 #CK Resource#G #EC AutoCloseable {\n" + "public void close() #TK #BK\n" + "}\n" + "class Test {\n" + "#S2 <X> void test() {\n" + "try (Resource#PK r = null) { }\n" + "}\n" + "}\n"; String source; public JavaSource() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); source = template.replace("#S1", suppress_decl.getSuppressAnno()) .replace("#S2", suppress_use.getSuppressAnno()) .replace("#CK", ck.kindName) .replace("#EC", ck.extendsClause) .replace("#G", ek_decl.getTypeParameter()) .replace("#TK", ek_decl.getThrowsClause()) .replace("#BK", ck.getBody()) .replace("#PK", ek_use.getTypeArguments(ek_decl)); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source)); ct.analyze(); check(); } void check() { boolean shouldWarnDecl = ek_decl.shouldWarn && xlint == XlintOption.TRY && suppress_decl != SuppressLevel.SUPPRESS; boolean shouldWarnUse = (ek_decl.shouldWarn || ((ek_use.shouldWarn || ek_use == ExceptionKind.NONE) && ek_decl == ExceptionKind.X)) && xlint == XlintOption.TRY && suppress_use != SuppressLevel.SUPPRESS; int foundWarnings = 0; if (shouldWarnDecl) foundWarnings++; if (shouldWarnUse) foundWarnings++; if (foundWarnings != diagChecker.tryWarnFound) { throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nOptions: " + xlint.getXlintOption() + "\nFound warnings: " + diagChecker.tryWarnFound + "\nExpected decl warning: " + shouldWarnDecl + "\nExpected use warning: " + shouldWarnUse); } } static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { int tryWarnFound; public void report(Diagnostic<? extends JavaFileObject> diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.WARNING && diagnostic.getCode().contains("try.resource.throws.interrupted.exc")) { tryWarnFound++; } } } }
8,014
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/importscope/A.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 4912075 4979456 * @summary static import of private field crashes compiler * @author gafter * * @compile A.java B.java */ package p1; public class A { public static char c = 'A'; }
1,264
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/importscope/B.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. */ package p2; import static p1.A.*; class X extends p1.A { private static char c = 'X'; } class B extends X { char x = c; // not X.c, but p1.A.c }
1,208
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T7085024.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/7085024/T7085024.java
/* * @test /nodynamiccopyright/ * @bug 7085024 * @summary internal error; cannot instantiate Foo * @compile/fail/ref=T7085024.out -XDrawDiagnostics T7085024.java */ class T7085024 { T7085024 (boolean ret) { } //internal error goes away if constructor accepts a reference type T7085024 f = new T7085024((NonExistentClass) null ); }
346
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6917288.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6917288/T6917288.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 6917288 * @summary Unnamed nested class is not generated */ import java.io.*; import java.util.*; public class T6917288 { // refers to kind of reference to an anon inner class that may be generated enum Kind { NONE, FALSE, TRUE, ALWAYS }; public static void main(String... args) throws Exception { new T6917288().run(); } void run() throws Exception { for (Kind k: Kind.values()) { test(k); } if (errors > 0) throw new Exception(errors + " errors occurred"); } /** * Run a test case for Kind k. */ void test(Kind k) throws Exception { System.err.println("Test " + (++count) + ": " + k); File testDir = new File("test" + count); File srcDir = new File(testDir, "src"); srcDir.mkdirs(); File classesDir = new File(testDir, "classes"); classesDir.mkdirs(); List<String> opts = new ArrayList<String>(); opts.add("-d"); opts.add(classesDir.getPath()); File f = writeFile(srcDir, k); int rc = compile(opts, f); if (rc != 0) { error("compilation failed: rc=" + rc); return; } check(classesDir, "Test.class", "Test$Inner.class", "Test$1.class"); } /** * Compile files with given options. * Display any output from compiler, and return javac return code. */ int compile(List<String> opts, File... files) { List<String> args = new ArrayList<String>(); args.addAll(opts); for (File f: files) args.add(f.getPath()); 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(); String out = sw.toString(); if (out.length() > 0) System.err.println(out); return rc; } /** * Check that a directory contains the expected files. */ void check(File dir, String... paths) { Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); if (found.equals(expect)) return; for (String f: found) { if (!expect.contains(f)) error("Unexpected file found: " + f); } for (String e: expect) { if (!found.contains(e)) error("Expected file not found: " + e); } } /** * Write source file for test case k. */ File writeFile(File dir, Kind k) throws Exception { StringBuilder sb = new StringBuilder(); sb.append("public class Test {\n"); sb.append(" private Inner inner;\n"); // generate different cases of an anon inner class if (k != Kind.NONE) { sb.append(" private void m() {\n"); sb.append(" "); switch (k) { case FALSE: case TRUE: sb.append("if (" + k.toString().toLowerCase() + ") "); } sb.append("new Runnable() { public void run() { } };\n"); sb.append(" }\n"); } sb.append(" private void init() {\n"); sb.append(" inner = new Inner();\n"); sb.append(" }\n"); sb.append("\n"); sb.append(" private static class Inner {\n"); sb.append(" private Inner() {\n"); sb.append(" }\n"); sb.append(" }\n"); sb.append("}\n"); File f = new File(dir, "Test.java"); FileWriter w = new FileWriter(f); w.write(sb.toString()); w.close(); return f; } /** * Record an error message. */ void error(String msg) { System.err.println(msg); errors++; } int count; int errors; }
5,005
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
GraphicalInstallerTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6917288/GraphicalInstallerTest.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 6917288 * @summary Unnamed nested class is not generated */ import java.io.*; import java.util.*; public class GraphicalInstallerTest { public static void main(String... args) throws Exception { new GraphicalInstallerTest().run(); } void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); File classes = new File("classes"); classes.mkdirs(); List<String> opts = Arrays.asList("-d", classes.getPath()); int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java")); if (rc != 0) { error("compilation failed: rc=" + rc); return; } check(classes, "GraphicalInstaller$1.class", "GraphicalInstaller$1X$1.class", "GraphicalInstaller$1X.class", "GraphicalInstaller$BackgroundInstaller.class", "GraphicalInstaller.class"); if (errors > 0) throw new Exception(errors + " errors occurred"); } /** * Compile files with given options. * Display any output from compiler, and return javac return code. */ int compile(List<String> opts, File... files) { List<String> args = new ArrayList<String>(); args.addAll(opts); for (File f: files) args.add(f.getPath()); 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(); String out = sw.toString(); if (out.length() > 0) System.err.println(out); return rc; } /** * Check that a directory contains the expected files. */ void check(File dir, String... paths) { Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); if (found.equals(expect)) return; for (String f: found) { if (!expect.contains(f)) error("Unexpected file found: " + f); } for (String e: expect) { if (!found.contains(e)) error("Expected file not found: " + e); } } /** * Record an error message. */ void error(String msg) { System.err.println(msg); errors++; } int errors; }
3,503
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
GraphicalInstaller.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6917288/GraphicalInstaller.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. */ /** * Complex example for the "access constructor tags" issue. * This test causes Lower to evaluate all classes defined in installNext * before they are lowered, thus preventing the use of Lower.classdefs * as a way of determining whether a class has been translated or not. */ class GraphicalInstaller { private BackgroundInstaller backgroundInstaller; private void installNext() { final Integer x = 0; class X { Object o = new Object() { int y = x; }; }; new X(); if (false) { new Runnable(){ public void run() { } }; } } private void installSuiteCommon() { backgroundInstaller = new BackgroundInstaller(); } private static class BackgroundInstaller { private BackgroundInstaller() { } } }
1,919
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTest2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/ClassPathTest2.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. */ import pkg.*; public class ClassPathTest2 { ClassPathTestAux2 x; }
1,125
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTest1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/ClassPathTest1.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. */ import pkg.*; public class ClassPathTest1 { ClassPathTestAux1 x; }
1,125
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTest3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/ClassPathTest3.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. */ import pkg.*; public class ClassPathTest3 { ClassPathTestAux3 x; }
1,125
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTestAux3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/pkg/ClassPathTestAux3.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. */ package pkg; public class ClassPathTestAux3 {}
1,100
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTestAux1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/foo/pkg/ClassPathTestAux1.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. */ package pkg; public class ClassPathTestAux1 {}
1,100
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ClassPathTestAux2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ClassPathTest/bar/pkg/ClassPathTestAux2.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. */ package pkg; public class ClassPathTestAux2 {}
1,100
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ConstructorAccess.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/ConstructorAccess.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. */ /* * @test * @bug 4116460 * @summary Test access methods for private constructors. * @author William Maddox (maddox) * * @compile ConstructorAccess.java * @run main ConstructorAccess */ public class ConstructorAccess { int i = 0; char c = 'x'; private ConstructorAccess() { this.i = 42; } private ConstructorAccess(int i, char c) { this.i = i; this.c = c; } class Inner { int j; char c; boolean b; private Inner() { this.j = 0; this.b = false; this.c = 'x'; } private Inner(int i, char c) { this.j = i; this.b = true; this.c = c; ConstructorAccess.this.i = i; } private Inner(int i, boolean b) { this.j = i; this.b = b; this.c = 'x'; } void foo() throws Exception { ConstructorAccess x = new ConstructorAccess(); if (x.i != 42 || x.c != 'x') { throw new Exception("error 1"); } ConstructorAccess y = new ConstructorAccess(555, 'y'); if (y.i != 555 || y.c != 'y') { throw new Exception("error2"); } } void check(int j, char c, boolean b) throws Exception { if (this.j != j || this.c != c || this.b != b) { throw new Exception("error3"); } } } void bar() throws Exception { Inner x = new Inner(); x.check(0, 'x', false); x.foo(); Inner y = new Inner(747, 'z'); y.check(747, 'z', true); if (this.i != 747) { throw new Exception("error 4"); } Inner z = new Inner(777, true); z.check(777, 'x' , true); } class InnerSub extends Inner { private InnerSub() { super(); } private InnerSub(int i) { super(i, 'w'); } private InnerSub(int i, boolean b) { super(i, b); } } public static void main(String[] args) throws Exception { ConstructorAccess o = new ConstructorAccess(); o.bar(); InnerSub x = o.new InnerSub(); x.check(0, 'x', false); x.foo(); InnerSub y = o.new InnerSub(767); y.check(767, 'w', true); if (o.i != 767) { throw new Exception("error 5"); } InnerSub z = o.new InnerSub(777, true); z.check(777, 'x' , true); } }
3,602
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
UplevelPrivateConstants.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/UplevelPrivateConstants.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. */ /* * @test * @bug 4098737 * @summary Compiler must treat an uplevel reference to a * private named constant as a constant expression. * * @compile UplevelPrivateConstants.java */ /* * Compilation will fail if the case labels are not * seen as constant expressions. */ class UplevelPrivateConstants { class Inner { private String value; Inner(int code) { switch(code) { case VAL1: value = "value1"; break; case VAL2: value = "value2"; break; case VAL3: value = "value3"; break; } } } private static final int VAL1 = 1; private static final int VAL2 = 2; private static final int VAL3 = 3; }
1,768
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ChainedAssignment.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/ChainedAssignment.java
/* * Copyright (c) 1998, 2001, 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 4098316 4522720 * @summary Test chained assignments using access methods. * @author William Maddox (maddox) * * @compile ChainedAssignment.java * @run main ChainedAssignment */ public class ChainedAssignment { private int a = 0; private int b = 0; private int c = 0; static private int sa = 0; static private int sb = 0; static private int sc = 0; private class Inner { void test1() throws Exception { (a) = (b) = 1; if (a != 1 || b != 1) { throw new Exception("FAILED (11)"); } System.out.println(a + " " + b + " " + c); a = b = c; if (a != 0 || b != 0) { throw new Exception("FAILED (12)"); } System.out.println(a + " " + b + " " + c); a = (b) += 5; if (a != 5 || b != 5) { throw new Exception("FAILED (13)"); } System.out.println(a + " " + b + " " + c); } void test2() throws Exception { sa = sb = 1; if (sa != 1 || sb != 1) { throw new Exception("FAILED (21)"); } System.out.println(sa + " " + sb + " " + sc); sa = sb = sc; if (sa != 0 || sb != 0) { throw new Exception("FAILED (22)"); } System.out.println(sa + " " + sb + " " + sc); sa = sb += 5; if (sa != 5 || sb != 5) { throw new Exception("FAILED (23)"); } System.out.println(sa + " " + sb + " " + sc); } } public static void main(String[] args) throws Exception { ChainedAssignment outer = new ChainedAssignment(); Inner inner = outer.new Inner(); inner.test1(); inner.test2(); } }
2,923
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
InternalHandshake.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/InternalHandshake.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 4430144 * @summary secret javac internal handshake for super access methods has side-effects. * * @author gafter * * @compile InternalHandshake.java * @run main InternalHandshake */ abstract class B { abstract void f(); void access$1() { this.f(); } } public class InternalHandshake extends B { void f() { System.out.println("correct"); } public static void main(String[] args) { new InternalHandshake().access$1(); } }
1,553
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
AccessMethodsLHS.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/AccessMethodsLHS.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. */ /* * @test * @bug 4102566 * @summary Test access methods for assignment targets. * @author William Maddox (maddox) * * @compile AccessMethodsLHS.java * @run main AccessMethodsLHS */ public class AccessMethodsLHS { static void fail(String msg) throws Exception { throw new Exception("FAIL: " + msg); } static int arg = 123456; private int i; private double d; private void m(int x) throws Exception { System.out.println("called AccessMethodsLHS.m"); if (x != 123456) AccessMethodsLHS.fail("bad argument"); } public static class Bar { private int i; private double d; private String s; private void m(int x) throws Exception { System.out.println("called AccessMethodsLHS.Bar.m"); if (x != 123456) AccessMethodsLHS.fail("bad argument"); } // Static members are permitted in a static inner class. static private int si; static private double sd; static private String ss; static private void sm(int x) throws Exception { System.out.println("called AccessMethodsLHS.Bar.sm"); if (x != 123456) AccessMethodsLHS.fail("bad argument"); } } public static class Baz { private int i; private double d; private String s; private void m(int x) throws Exception { System.out.println("called Baz.m"); if (x != 123456) AccessMethodsLHS.fail("bad argument"); } // Compiler rejects static members here correctly. // static private int si; // static private double sd; // static private String ss; } public class Quux { void DoIt () throws Exception { m(arg); i = 1; d = 1.0; i += 5; i--; } void DoMore(AccessMethodsLHS f) throws Exception { f.m(arg); } } public static class Quem { void DoIt () { // Illegal static refs to non-static vars // i = 1; // d = 1.0; // i += 5; // i--; } } static int effects = 0; static Bar iBar(Bar x) { effects++; return x; } static Baz iBaz(Baz x) { effects++; return x; } static void checkEffects(int i) throws Exception { if (effects != 1) { AccessMethodsLHS.fail("incorrect side-effect behavior (" + effects + "): " + i); } effects = 0; } static public void main(String args[]) throws Exception { Bar b = new Bar(); Baz c = new Baz(); System.out.println("testing assignment"); AccessMethodsLHS f = new AccessMethodsLHS(); Quux q1 = f.new Quux(); q1.DoIt(); q1.DoMore(f); Quem q2 = new Quem(); q2.DoIt(); // *** Static class, Non-static members *** b.m(arg); // Integer (1 word) b.i = 5; System.out.println(b.i); if (b.i != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.i); if ((b.i += 10) != 15) AccessMethodsLHS.fail("add-assign result"); System.out.println(b.i); if (b.i != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.i); b.s = "foo"; if (!(b.s += "bar").equals("foobar")) AccessMethodsLHS.fail("concat-assign result"); System.out.println(b.s); if (!b.s.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect"); System.out.println(b.s); b.s = "foo"; b.s += "bar"; if (!b.s.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect (novalue)"); System.out.println(b.s); b.i = 0; b.i++; if (b.i != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.i); b.i = 5; if (b.i++ != 5) AccessMethodsLHS.fail("post-increment result"); if (b.i != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.i); b.i = 1; --b.i; if (b.i != 0) AccessMethodsLHS.fail("pre-decrement effect"); b.i = 5; if (--b.i != 4) AccessMethodsLHS.fail("pre-decrement result"); if (b.i != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.i); // Double (2 word) b.d = 5.0; System.out.println(b.d); if (b.d != 5.0) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.d); if ((b.d += 10) != 15.0) AccessMethodsLHS.fail("add-assign result"); System.out.println(b.d); if (b.d != 15.0) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.d); b.d = 0.0; b.d++; if (b.d != 1.0) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.d); b.d = 5.0; if (b.d++ != 5.0) AccessMethodsLHS.fail("post-increment result"); if (b.d != 6.0) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.d); b.d = 1.0; --b.d; if (b.d != 0.0) AccessMethodsLHS.fail("pre-decrement effect"); b.d = 5.0; if (--b.d != 4.0) AccessMethodsLHS.fail("pre-decrement result"); if (b.d != 4.0) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.d); // Integer (1 word) with side-effects in object reference iBar(b).i = 5; checkEffects(1); System.out.println(b.i); if (b.i != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.i); if ((iBar(b).i += 10) != 15) AccessMethodsLHS.fail("add-assign result"); checkEffects(2); System.out.println(b.i); if (b.i != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.i); b.i = 0; iBar(b).i++; checkEffects(3); if (b.i != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.i); b.i = 5; if (iBar(b).i++ != 5) AccessMethodsLHS.fail("post-increment result"); checkEffects(4); if (b.i != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.i); b.i = 1; --iBar(b).i; checkEffects(5); if (b.i != 0) AccessMethodsLHS.fail("pre-decrement effect"); b.i = 5; if (--iBar(b).i != 4) AccessMethodsLHS.fail("pre-decrement result"); checkEffects(6); if (b.i != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.i); // *** Static class, Static members *** Bar.sm(arg); // Integer (1 word) Bar.si = 5; System.out.println(Bar.si); if (Bar.si != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(Bar.si); if ((Bar.si += 10) != 15) AccessMethodsLHS.fail("add-assign result"); System.out.println(Bar.si); if (Bar.si != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(Bar.si); Bar.ss = "foo"; if (!(Bar.ss += "bar").equals("foobar")) AccessMethodsLHS.fail("concat-assign result"); System.out.println(Bar.ss); if (!Bar.ss.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect"); System.out.println(Bar.ss); Bar.ss = "foo"; Bar.ss += "bar"; if (!Bar.ss.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect (novalue)"); System.out.println(Bar.ss); Bar.si = 0; Bar.si++; if (Bar.si != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(Bar.si); Bar.si = 5; if (Bar.si++ != 5) AccessMethodsLHS.fail("post-increment result"); if (Bar.si != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(Bar.si); Bar.si = 1; --Bar.si; if (Bar.si != 0) AccessMethodsLHS.fail("pre-decrement effect"); Bar.si = 5; if (--Bar.si != 4) AccessMethodsLHS.fail("pre-decrement result"); if (Bar.si != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(Bar.si); // Double (2 word) Bar.sd = 5.0; System.out.println(Bar.sd); if (Bar.sd != 5.0) AccessMethodsLHS.fail("simple assignment"); System.out.println(Bar.sd); if ((Bar.sd += 10) != 15.0) AccessMethodsLHS.fail("add-assign result"); System.out.println(Bar.sd); if (Bar.sd != 15.0) AccessMethodsLHS.fail("add-assign effect"); System.out.println(Bar.sd); Bar.sd = 0.0; Bar.sd++; if (Bar.sd != 1.0) AccessMethodsLHS.fail("post-increment effect"); System.out.println(Bar.sd); Bar.sd = 5.0; if (Bar.sd++ != 5.0) AccessMethodsLHS.fail("post-increment result"); if (Bar.sd != 6.0) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(Bar.sd); Bar.sd = 1.0; --Bar.sd; if (Bar.sd != 0.0) AccessMethodsLHS.fail("pre-decrement effect"); Bar.sd = 5.0; if (--Bar.sd != 4.0) AccessMethodsLHS.fail("pre-decrement result"); if (Bar.sd != 4.0) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(Bar.sd); // *** Static class, Static members (invoked via object reference) *** b.sm(arg); iBar(b).sm(arg); checkEffects(101); // Integer (1 word) b.si = 5; System.out.println(b.si); if (b.si != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.si); if ((b.si += 10) != 15) AccessMethodsLHS.fail("add-assign result"); System.out.println(b.si); if (b.si != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.si); b.ss = "foo"; if (!(b.ss += "bar").equals("foobar")) AccessMethodsLHS.fail("concat-assign result"); System.out.println(b.ss); if (!b.ss.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect"); System.out.println(b.ss); b.ss = "foo"; b.ss += "bar"; if (!b.ss.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect (novalue)"); System.out.println(b.ss); b.si = 0; b.si++; if (b.si != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.si); b.si = 5; if (b.si++ != 5) AccessMethodsLHS.fail("post-increment result"); if (b.si != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.si); b.si = 1; --b.si; if (b.si != 0) AccessMethodsLHS.fail("pre-decrement effect"); b.si = 5; if (--b.si != 4) AccessMethodsLHS.fail("pre-decrement result"); if (b.si != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.si); // Double (2 word) b.sd = 5.0; System.out.println(b.sd); if (b.sd != 5.0) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.sd); if ((b.sd += 10) != 15.0) AccessMethodsLHS.fail("add-assign result"); System.out.println(b.sd); if (b.sd != 15.0) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.sd); b.sd = 0.0; b.sd++; if (b.sd != 1.0) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.sd); b.sd = 5.0; if (b.sd++ != 5.0) AccessMethodsLHS.fail("post-increment result"); if (b.sd != 6.0) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.sd); b.sd = 1.0; --b.sd; if (b.sd != 0.0) AccessMethodsLHS.fail("pre-decrement effect"); b.sd = 5.0; if (--b.sd != 4.0) AccessMethodsLHS.fail("pre-decrement result"); if (b.sd != 4.0) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.sd); // Integer (1 word) with side-effects in object reference iBar(b).si = 5; checkEffects(7); System.out.println(b.si); if (b.si != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(b.si); if ((iBar(b).si += 10) != 15) AccessMethodsLHS.fail("add-assign result"); checkEffects(8); System.out.println(b.si); if (b.si != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(b.si); iBar(b).si = 0; checkEffects(9); iBar(b).si++; checkEffects(10); if (b.si != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(b.si); b.si = 5; if (iBar(b).si++ != 5) AccessMethodsLHS.fail("post-increment result"); checkEffects(11); if (b.si != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(b.si); b.si = 1; --iBar(b).si; checkEffects(12); if (b.si != 0) AccessMethodsLHS.fail("pre-decrement effect"); b.si = 5; if (--iBar(b).si != 4) AccessMethodsLHS.fail("pre-decrement result"); checkEffects(13); if (b.si != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(b.si); // *** Non-static class, Non-static members *** c.m(arg); iBaz(c).m(arg); checkEffects(102); // Integer (1 word) c.i = 5; System.out.println(c.i); if (c.i != 5) AccessMethodsLHS.fail("simple assignment"); System.out.println(c.i); if ((c.i += 10) != 15) AccessMethodsLHS.fail("add-assign result"); System.out.println(c.i); if (c.i != 15) AccessMethodsLHS.fail("add-assign effect"); System.out.println(c.i); c.s = "foo"; if (!(c.s += "bar").equals("foobar")) AccessMethodsLHS.fail("concat-assign result"); System.out.println(c.s); if (!c.s.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect"); System.out.println(c.s); c.s = "foo"; c.s += "bar"; if (!c.s.equals("foobar")) AccessMethodsLHS.fail("concat-assign effect (novalue)"); System.out.println(c.s); c.i = 0; c.i++; if (c.i != 1) AccessMethodsLHS.fail("post-increment effect"); System.out.println(c.i); c.i = 5; if (c.i++ != 5) AccessMethodsLHS.fail("post-increment result"); if (c.i != 6) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(c.i); c.i = 1; --c.i; if (c.i != 0) AccessMethodsLHS.fail("pre-decrement effect"); c.i = 5; if (--c.i != 4) AccessMethodsLHS.fail("pre-decrement result"); if (c.i != 4) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(c.i); // Double (2 word) c.d = 5.0; System.out.println(c.d); if (c.d != 5.0) AccessMethodsLHS.fail("simple assignment"); System.out.println(c.d); if ((c.d += 10) != 15.0) AccessMethodsLHS.fail("add-assign result"); System.out.println(c.d); if (c.d != 15.0) AccessMethodsLHS.fail("add-assign effect"); System.out.println(c.d); c.d = 0.0; c.d++; if (c.d != 1.0) AccessMethodsLHS.fail("post-increment effect"); System.out.println(c.d); c.d = 5.0; if (c.d++ != 5.0) AccessMethodsLHS.fail("post-increment result"); if (c.d != 6.0) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(c.d); c.d = 1.0; --c.d; if (c.d != 0.0) AccessMethodsLHS.fail("pre-decrement effect"); c.d = 5.0; if (--c.d != 4.0) AccessMethodsLHS.fail("pre-decrement result"); if (c.d != 4.0) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(c.d); // Double (2 word) with side-effects in object reference iBaz(c).d = 5.0; checkEffects(14); System.out.println(c.d); if (c.d != 5.0) AccessMethodsLHS.fail("simple assignment"); System.out.println(c.d); if ((iBaz(c).d += 10) != 15.0) AccessMethodsLHS.fail("add-assign result"); checkEffects(15); System.out.println(c.d); if (c.d != 15.0) AccessMethodsLHS.fail("add-assign effect"); System.out.println(c.d); c.d = 0.0; iBaz(c).d++; checkEffects(16); if (c.d != 1.0) AccessMethodsLHS.fail("post-increment effect"); System.out.println(c.d); c.d = 5.0; if (iBaz(c).d++ != 5.0) AccessMethodsLHS.fail("post-increment result"); checkEffects(17); if (c.d != 6.0) AccessMethodsLHS.fail("post-increment effect (embedded)"); System.out.println(c.d); c.d = 1.0; --iBaz(c).d; checkEffects(18); if (c.d != 0.0) AccessMethodsLHS.fail("pre-decrement effect"); c.d = 5.0; if (--iBaz(c).d != 4.0) AccessMethodsLHS.fail("pre-decrement result"); checkEffects(19); if (c.d != 4.0) AccessMethodsLHS.fail("pre-decrement effect (embedded)"); System.out.println(c.d); // All done. System.out.println("done"); } }
20,007
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
LateAddition.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/LateAddition.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. */ /* * @test * @bug 4098093 * @summary Compiler must properly handle access methods * created after their class has been checked. * * @compile LateAddition.java */ /* * This is the example submitted in the bug report. * It should compile successfully. * Future changes to the compiler may affect the timing * of the creation of access methods, making it an unreliable * test of the condition described in the summary. */ public class LateAddition { public int f() { class Local { private int i = 5; } return (new Local()).i; } }
1,638
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BitwiseAssignment.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/AccessMethods/BitwiseAssignment.java
/* * Copyright (c) 2001, 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 4387704 * @summary Check correct generation of bitwise assignment access method. * @author Neal Gafter (gafter) * * @compile BitwiseAssignment.java * @run main BitwiseAssignment */ public class BitwiseAssignment { private static class Inner { private int data = 4711; } public static void main(String[] args) { { Inner inner1 = new Inner(); inner1.data ^= 42; Inner inner2 = new Inner(); inner2.data = inner2.data ^ 42; if (inner1.data != inner2.data) throw new Error("Failed inner ^="); } { Inner inner1 = new Inner(); inner1.data |= 42; Inner inner2 = new Inner(); inner2.data = inner2.data | 42; if (inner1.data != inner2.data) throw new Error("Failed inner |="); } { Inner inner1 = new Inner(); inner1.data &= 4211; Inner inner2 = new Inner(); inner2.data = inner2.data & 4211; if (inner1.data != inner2.data) throw new Error("Failed inner &="); } } }
2,193
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
StringFoldingTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/parser/StringFoldingTest.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 7068902 * @summary verify that string folding can be enabled or disabled */ import com.sun.source.tree.CompilationUnitTree; import com.sun.source.util.JavacTask; import java.io.File; import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.ToolProvider; public class StringFoldingTest { final JavaCompiler tool; final JavaSource source; public StringFoldingTest() { tool = ToolProvider.getSystemJavaCompiler(); source = new JavaSource(); } static class JavaSource extends SimpleJavaFileObject { final static String source = "class C {String X=\"F\" + \"O\" + \"L\" + \"D\" + \"E\" + \"D\";}"; JavaSource() { super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } public static void main(String... args) throws IOException { StringFoldingTest t = new StringFoldingTest(); t.run(false); t.run(true); } void run(boolean disableStringFolding) throws IOException { List<String> argsList = new ArrayList<String>(); if (disableStringFolding) { argsList.add("-XDallowStringFolding=false"); } JavacTask ct = (JavacTask)tool.getTask(null, null, null, argsList, null, Arrays.asList(source)); Iterable<? extends CompilationUnitTree> trees = ct.parse(); String text = trees.toString(); System.out.println(text); if (disableStringFolding) { if (text.contains("FOLDED")) { throw new AssertionError("Expected string folding"); } } else { if (!text.contains("FOLDED")) { throw new AssertionError("Expected no string folding"); } } } }
3,192
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ExtraSemiTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/parser/ExtraSemiTest.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 6921495 * @summary spurious semicolons in class def cause empty NOPOS blocks */ import java.io.*; import java.net.*; import java.util.*; import javax.tools.*; import com.sun.source.util.*; public class ExtraSemiTest { static class JavaSource extends SimpleJavaFileObject { final static String source = "class C {\n" + " int x;;\n" + " class X { int i;; };\n" + "}"; JavaSource() { super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE); } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return source; } } public static void main(String... args) throws IOException { new ExtraSemiTest().run(); } void run() throws IOException { File destDir = new File("classes"); destDir.mkdir(); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavaSource source = new JavaSource(); JavacTask ct = (JavacTask)tool.getTask(null, null, null, Arrays.asList("-d", destDir.getPath(), "-XD-printsource"), null, Arrays.asList(source)); Boolean ok = ct.call(); if (!ok) throw new AssertionError("compilation failed"); String text = readFile(new File(destDir, "C.java")); System.out.println(text); // compress/canonicalize all whitespace String canon = text.replaceAll("\\s+", " "); System.out.println("canon: " + canon); // There are no empty blocks in the original text. // C will be given a default constructor "C() { super(); }" which // does not have any empty blocks. // The bug is that spurious semicolons in the class defn are parsed // into redundant empty blocks in the tree, so verify there are // no empty blocks in the -printsource output if (canon.contains("{ }")) throw new AssertionError("unexpected empty block found"); } String readFile(File f) throws IOException { int len = (int) f.length(); byte[] data = new byte[len]; DataInputStream in = new DataInputStream(new FileInputStream(f)); try { in.readFully(data); return new String(data); } finally { in.close(); } } }
3,504
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
JavacParserTest.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/parser/netbeans/JavacParserTest.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 7073631 * @summary tests error and diagnostics positions * @author jan.lahoda@oracle.com */ import com.sun.source.tree.BinaryTree; import com.sun.source.tree.BlockTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.ExpressionStatementTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.ModifiersTree; import com.sun.source.tree.StatementTree; import com.sun.source.tree.Tree; import com.sun.source.tree.Tree.Kind; import com.sun.source.tree.VariableTree; import com.sun.source.tree.WhileLoopTree; import com.sun.source.util.SourcePositions; import com.sun.source.util.TreeScanner; import com.sun.source.util.Trees; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.tree.JCTree; import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import javax.tools.Diagnostic; import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticListener; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import javax.tools.ToolProvider; public class JavacParserTest extends TestCase { final JavaCompiler tool; public JavacParserTest(String testName) { tool = ToolProvider.getSystemJavaCompiler(); System.out.println("java.home=" + System.getProperty("java.home")); } static class MyFileObject extends SimpleJavaFileObject { private String text; public MyFileObject(String text) { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); this.text = text; } @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { return text; } } public void testPositionForSuperConstructorCalls() throws IOException { assert tool != null; String code = "package test; public class Test {public Test() {super();}}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); SourcePositions pos = Trees.instance(ct).getSourcePositions(); MethodTree method = (MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); ExpressionStatementTree es = (ExpressionStatementTree) method.getBody().getStatements().get(0); assertEquals("testPositionForSuperConstructorCalls", 72 - 24, pos.getStartPosition(cut, es)); assertEquals("testPositionForSuperConstructorCalls", 80 - 24, pos.getEndPosition(cut, es)); MethodInvocationTree mit = (MethodInvocationTree) es.getExpression(); assertEquals("testPositionForSuperConstructorCalls", 72 - 24, pos.getStartPosition(cut, mit)); assertEquals("testPositionForSuperConstructorCalls", 79 - 24, pos.getEndPosition(cut, mit)); assertEquals("testPositionForSuperConstructorCalls", 72 - 24, pos.getStartPosition(cut, mit.getMethodSelect())); assertEquals("testPositionForSuperConstructorCalls", 77 - 24, pos.getEndPosition(cut, mit.getMethodSelect())); } public void testPositionForEnumModifiers() throws IOException { String code = "package test; public enum Test {A;}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); SourcePositions pos = Trees.instance(ct).getSourcePositions(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); ModifiersTree mt = clazz.getModifiers(); assertEquals("testPositionForEnumModifiers", 38 - 24, pos.getStartPosition(cut, mt)); assertEquals("testPositionForEnumModifiers", 44 - 24, pos.getEndPosition(cut, mt)); } public void testNewClassWithEnclosing() throws IOException { String code = "package test; class Test { " + "class d {} private void method() { " + "Object o = Test.this.new d(); } }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); SourcePositions pos = Trees.instance(ct).getSourcePositions(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); ExpressionTree est = ((VariableTree) ((MethodTree) clazz.getMembers().get(1)).getBody().getStatements().get(0)).getInitializer(); assertEquals("testNewClassWithEnclosing", 97 - 24, pos.getStartPosition(cut, est)); assertEquals("testNewClassWithEnclosing", 114 - 24, pos.getEndPosition(cut, est)); } public void testPreferredPositionForBinaryOp() throws IOException { String code = "package test; public class Test {" + "private void test() {" + "Object o = null; boolean b = o != null && o instanceof String;" + "} private Test() {}}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(0); VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1); BinaryTree cond = (BinaryTree) condSt.getInitializer(); JCTree condJC = (JCTree) cond; assertEquals("testNewClassWithEnclosing", 117 - 24, condJC.pos); } public void testPositionBrokenSource126732a() throws IOException { String[] commands = new String[]{ "return Runnable()", "do { } while (true)", "throw UnsupportedOperationException()", "assert true", "1 + 1",}; for (String command : commands) { String code = "package test;\n" + "public class Test {\n" + " public static void test() {\n" + " " + command + " {\n" + " new Runnable() {\n" + " };\n" + " }\n" + "}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(0); List<? extends StatementTree> statements = method.getBody().getStatements(); StatementTree ret = statements.get(0); StatementTree block = statements.get(1); Trees t = Trees.instance(ct); int len = code.indexOf(command + " {") + (command + " ").length(); assertEquals(command, len, t.getSourcePositions().getEndPosition(cut, ret)); assertEquals(command, len, t.getSourcePositions().getStartPosition(cut, block)); } } public void testPositionBrokenSource126732b() throws IOException { String[] commands = new String[]{ "break", "break A", "continue ", "continue A",}; for (String command : commands) { String code = "package test;\n" + "public class Test {\n" + " public static void test() {\n" + " while (true) {\n" + " " + command + " {\n" + " new Runnable() {\n" + " };\n" + " }\n" + " }\n" + "}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(0); List<? extends StatementTree> statements = ((BlockTree) ((WhileLoopTree) method.getBody().getStatements().get(0)).getStatement()).getStatements(); StatementTree ret = statements.get(0); StatementTree block = statements.get(1); Trees t = Trees.instance(ct); int len = code.indexOf(command + " {") + (command + " ").length(); assertEquals(command, len, t.getSourcePositions().getEndPosition(cut, ret)); assertEquals(command, len, t.getSourcePositions().getStartPosition(cut, block)); } } public void testErrorRecoveryForEnhancedForLoop142381() throws IOException { String code = "package test; class Test { " + "private void method() { " + "java.util.Set<String> s = null; for (a : s) {} } }"; final List<Diagnostic<? extends JavaFileObject>> errors = new LinkedList<Diagnostic<? extends JavaFileObject>>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic<? extends JavaFileObject> diagnostic) { errors.add(diagnostic); } }, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); StatementTree forStatement = ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); assertEquals("testErrorRecoveryForEnhancedForLoop142381", Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); } public void testPositionAnnotationNoPackage187551() throws IOException { String code = "\n@interface Test {}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); Trees t = Trees.instance(ct); assertEquals("testPositionAnnotationNoPackage187551", 1, t.getSourcePositions().getStartPosition(cut, clazz)); } public void testPositionsSane() throws IOException { performPositionsSanityTest("package test; class Test { " + "private void method() { " + "java.util.List<? extends java.util.List<? extends String>> l; " + "} }"); performPositionsSanityTest("package test; class Test { " + "private void method() { " + "java.util.List<? super java.util.List<? super String>> l; " + "} }"); performPositionsSanityTest("package test; class Test { " + "private void method() { " + "java.util.List<? super java.util.List<?>> l; } }"); } private void performPositionsSanityTest(String code) throws IOException { final List<Diagnostic<? extends JavaFileObject>> errors = new LinkedList<Diagnostic<? extends JavaFileObject>>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic<? extends JavaFileObject> diagnostic) { errors.add(diagnostic); } }, null, null, Arrays.asList(new MyFileObject(code))); final CompilationUnitTree cut = ct.parse().iterator().next(); final Trees trees = Trees.instance(ct); new TreeScanner<Void, Void>() { private long parentStart = 0; private long parentEnd = Integer.MAX_VALUE; @Override public Void scan(Tree node, Void p) { if (node == null) { return null; } long start = trees.getSourcePositions().getStartPosition(cut, node); if (start == (-1)) { return null; //synthetic tree } assertTrue(node.toString() + ":" + start + "/" + parentStart, parentStart <= start); long prevParentStart = parentStart; parentStart = start; long end = trees.getSourcePositions().getEndPosition(cut, node); assertTrue(node.toString() + ":" + end + "/" + parentEnd, end <= parentEnd); long prevParentEnd = parentEnd; parentEnd = end; super.scan(node, p); parentStart = prevParentStart; parentEnd = prevParentEnd; return null; } private void assertTrue(String message, boolean b) { if (!b) fail(message); } }.scan(cut, null); } public void testCorrectWilcardPositions() throws IOException { performWildcardPositionsTest("package test; import java.util.List; " + "class Test { private void method() { List<? extends List<? extends String>> l; } }", Arrays.asList("List<? extends List<? extends String>> l;", "List<? extends List<? extends String>>", "List", "? extends List<? extends String>", "List<? extends String>", "List", "? extends String", "String")); performWildcardPositionsTest("package test; import java.util.List; " + "class Test { private void method() { List<? super List<? super String>> l; } }", Arrays.asList("List<? super List<? super String>> l;", "List<? super List<? super String>>", "List", "? super List<? super String>", "List<? super String>", "List", "? super String", "String")); performWildcardPositionsTest("package test; import java.util.List; " + "class Test { private void method() { List<? super List<?>> l; } }", Arrays.asList("List<? super List<?>> l;", "List<? super List<?>>", "List", "? super List<?>", "List<?>", "List", "?")); performWildcardPositionsTest("package test; import java.util.List; " + "class Test { private void method() { " + "List<? extends List<? extends List<? extends String>>> l; } }", Arrays.asList("List<? extends List<? extends List<? extends String>>> l;", "List<? extends List<? extends List<? extends String>>>", "List", "? extends List<? extends List<? extends String>>", "List<? extends List<? extends String>>", "List", "? extends List<? extends String>", "List<? extends String>", "List", "? extends String", "String")); performWildcardPositionsTest("package test; import java.util.List; " + "class Test { private void method() { " + "List<? extends List<? extends List<? extends String >>> l; } }", Arrays.asList("List<? extends List<? extends List<? extends String >>> l;", "List<? extends List<? extends List<? extends String >>>", "List", "? extends List<? extends List<? extends String >>", "List<? extends List<? extends String >>", "List", "? extends List<? extends String >", "List<? extends String >", "List", "? extends String", "String")); } public void performWildcardPositionsTest(final String code, List<String> golden) throws IOException { final List<Diagnostic<? extends JavaFileObject>> errors = new LinkedList<Diagnostic<? extends JavaFileObject>>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic<? extends JavaFileObject> diagnostic) { errors.add(diagnostic); } }, null, null, Arrays.asList(new MyFileObject(code))); final CompilationUnitTree cut = ct.parse().iterator().next(); final List<String> content = new LinkedList<String>(); final Trees trees = Trees.instance(ct); new TreeScanner<Void, Void>() { @Override public Void scan(Tree node, Void p) { if (node == null) { return null; } long start = trees.getSourcePositions().getStartPosition(cut, node); if (start == (-1)) { return null; //synthetic tree } long end = trees.getSourcePositions().getEndPosition(cut, node); String s = code.substring((int) start, (int) end); content.add(s); return super.scan(node, p); } }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); assertEquals("performWildcardPositionsTest",golden.toString(), content.toString()); } public void testStartPositionForMethodWithoutModifiers() throws IOException { String code = "package t; class Test { <T> void t() {} }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree mt = (MethodTree) clazz.getMembers().get(0); Trees t = Trees.instance(ct); int start = (int) t.getSourcePositions().getStartPosition(cut, mt); int end = (int) t.getSourcePositions().getEndPosition(cut, mt); assertEquals("testStartPositionForMethodWithoutModifiers", "<T> void t() {}", code.substring(start, end)); } public void testStartPositionEnumConstantInit() throws IOException { String code = "package t; enum Test { AAA; }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); VariableTree enumAAA = (VariableTree) clazz.getMembers().get(0); Trees t = Trees.instance(ct); int start = (int) t.getSourcePositions().getStartPosition(cut, enumAAA.getInitializer()); assertEquals("testStartPositionEnumConstantInit", -1, start); } public void testVariableInIfThen1() throws IOException { String code = "package t; class Test { " + "private static void t(String name) { " + "if (name != null) String nn = name.trim(); } }"; DiagnosticCollector<JavaFileObject> coll = new DiagnosticCollector<JavaFileObject>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, null, Arrays.asList(new MyFileObject(code))); ct.parse(); List<String> codes = new LinkedList<String>(); for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { codes.add(d.getCode()); } assertEquals("testVariableInIfThen1", Arrays.<String>asList("compiler.err.variable.not.allowed"), codes); } public void testVariableInIfThen2() throws IOException { String code = "package t; class Test { " + "private static void t(String name) { " + "if (name != null) class X {} } }"; DiagnosticCollector<JavaFileObject> coll = new DiagnosticCollector<JavaFileObject>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, null, Arrays.asList(new MyFileObject(code))); ct.parse(); List<String> codes = new LinkedList<String>(); for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { codes.add(d.getCode()); } assertEquals("testVariableInIfThen2", Arrays.<String>asList("compiler.err.class.not.allowed"), codes); } public void testVariableInIfThen3() throws IOException { String code = "package t; class Test { "+ "private static void t(String name) { " + "if (name != null) abstract } }"; DiagnosticCollector<JavaFileObject> coll = new DiagnosticCollector<JavaFileObject>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, null, Arrays.asList(new MyFileObject(code))); ct.parse(); List<String> codes = new LinkedList<String>(); for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { codes.add(d.getCode()); } assertEquals("testVariableInIfThen3", Arrays.<String>asList("compiler.err.illegal.start.of.expr"), codes); } //see javac bug #6882235, NB bug #98234: public void testMissingExponent() throws IOException { String code = "\nclass Test { { System.err.println(0e); } }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); assertNotNull(ct.parse().iterator().next()); } public void testTryResourcePos() throws IOException { final String code = "package t; class Test { " + "{ try (java.io.InputStream in = null) { } } }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); new TreeScanner<Void, Void>() { @Override public Void visitVariable(VariableTree node, Void p) { if ("in".contentEquals(node.getName())) { JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; System.out.println(node.getName() + "," + var.pos); assertEquals("testTryResourcePos", "in = null) { } } }", code.substring(var.pos)); } return super.visitVariable(node, p); } }.scan(cut, null); } public void testVarPos() throws IOException { final String code = "package t; class Test { " + "{ java.io.InputStream in = null; } }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); new TreeScanner<Void, Void>() { @Override public Void visitVariable(VariableTree node, Void p) { if ("in".contentEquals(node.getName())) { JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; assertEquals("testVarPos","in = null; } }", code.substring(var.pos)); } return super.visitVariable(node, p); } }.scan(cut, null); } void testsNotWorking() throws IOException { // Fails with nb-javac, needs further investigation testPositionBrokenSource126732a(); testPositionBrokenSource126732b(); // Fails, these tests yet to be addressed testVariableInIfThen1(); testVariableInIfThen2(); testPositionForEnumModifiers(); testStartPositionEnumConstantInit(); } void testPositions() throws IOException { testPositionsSane(); testCorrectWilcardPositions(); testPositionAnnotationNoPackage187551(); testPositionForSuperConstructorCalls(); testPreferredPositionForBinaryOp(); testStartPositionForMethodWithoutModifiers(); testVarPos(); testVariableInIfThen3(); testTryResourcePos(); } public static void main(String... args) throws IOException { JavacParserTest jpt = new JavacParserTest("JavacParserTest"); jpt.testPositions(); System.out.println("PASS"); } } abstract class TestCase { void assertEquals(String message, int i, int pos) { if (i != pos) { fail(message); } } void assertFalse(String message, boolean empty) { throw new UnsupportedOperationException("Not yet implemented"); } void assertEquals(String message, int i, long l) { if (i != l) { fail(message + ":" + i + ":" + l); } } void assertEquals(String message, Object o1, Object o2) { System.out.println(o1); System.out.println(o2); if (o1 != null && o2 != null && !o1.equals(o2)) { fail(message); } if (o1 == null && o2 != null) { fail(message); } } void assertNotNull(Object o) { if (o == null) { fail(); } } void fail() { fail("test failed"); } void fail(String message) { throw new RuntimeException(message); } }
27,791
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6758789b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6758789/T6758789b.java
/* * @test /nodynamiccopyright/ * @bug 6758789 * @summary 6758789: Some method resolution diagnostic should be improved * @author Maurizio Cimadamore * * @compile/fail/ref=T6758789b.out -Werror -XDrawDiagnostics -Xlint:unchecked T6758789b.java */ class T6758789a { class Foo<T> {} <X> void m(Foo<X> foo) {} void test() { m(new Foo()); } }
373
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6758789a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6758789/T6758789a.java
/* * @test /nodynamiccopyright/ * @bug 6758789 * @summary 6758789: Some method resolution diagnostic should be improved * @author Maurizio Cimadamore * * @compile/fail/ref=T6758789a.out -XDrawDiagnostics T6758789a.java */ class T6758789a { void m1() {} void m2(int i) {} void test() { m1(1); m2(); } }
342
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
AS.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/p1/AS.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. */ /* * Auxiliary file for QualifiedThisAndSuper_1.java, et. al. */ package p1; public class AS { protected String u = "asu"; protected String o() { return "aso"; } }
1,228
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BS.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/p1/BS.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. */ /* * Auxiliary file for QualifiedThisAndSuper_1.java, et. al. */ package p1; public class BS { protected String u = "bsu"; protected String o() { return "bso"; } }
1,228
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CS.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/p1/CS.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. */ /* * Auxiliary file for QualifiedThisAndSuper_1.java, et. al. */ package p1; public class CS { protected String u = "csu"; protected String o() { return "cso"; } }
1,228
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/4980495/static/Test.java
/* * @test /nodynamiccopyright/ * @bug 4980495 6260444 * @compile/fail/ref=Test.out -XDrawDiagnostics Test.java p1/A1.java p2/A2.java */ package p; import static p1.A1.f; import static p2.A2.f; public class Test { public static void main(String argv[]) { f = 1; } }
291
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4980495/static/p1/A1.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. */ package p1; public class A1 { static public int f = 6; }
1,114
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4980495/static/p2/A2.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. */ package p2; public class A2 { static public int f = 6; }
1,114
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/4980495/std/Test.java
/* * @test /nodynamiccopyright/ * @bug 4980495 6260444 * @compile/fail/ref=Test.out -XDrawDiagnostics Test.java p1/A1.java p2/A2.java * */ package p; import p1.A1.f; import p2.A2.f; public class Test { public static void main(String argv[]) { new f(); } }
282
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4980495/std/p1/A1.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. */ package p1; public class A1 { static public class f { }; }
1,116
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
A2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4980495/std/p2/A2.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. */ package p2; public class A2 { static public class f { }; }
1,116
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Test256b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4917091/Test256b.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 4917091 * @summary javac rejects array over 128 in length * @compile/fail/ref=Test256b.out -XDrawDiagnostics Test256b.java */ public class Test256b { // allocating an array with 255 dimensions whose component // type provides additional dimensions is not allowed, // since the type descriptor for any array is limited to // 255 dimensions: JVMS3, section 4.3.2. static Object expected = (Object)new Object [1/*001*/][1/*002*/][1/*003*/][1/*004*/][1/*005*/] [1/*006*/][1/*007*/][1/*008*/][1/*009*/][1/*010*/] [1/*011*/][1/*012*/][1/*013*/][1/*014*/][1/*015*/] [1/*016*/][1/*017*/][1/*018*/][1/*019*/][1/*020*/] [1/*021*/][1/*022*/][1/*023*/][1/*024*/][1/*025*/] [1/*026*/][1/*027*/][1/*028*/][1/*029*/][1/*030*/] [1/*031*/][1/*032*/][1/*033*/][1/*034*/][1/*035*/] [1/*036*/][1/*037*/][1/*038*/][1/*039*/][1/*040*/] [1/*041*/][1/*042*/][1/*043*/][1/*044*/][1/*045*/] [1/*046*/][1/*047*/][1/*048*/][1/*049*/][1/*050*/] [1/*051*/][1/*052*/][1/*053*/][1/*054*/][1/*055*/] [1/*056*/][1/*057*/][1/*058*/][1/*059*/][1/*060*/] [1/*061*/][1/*062*/][1/*063*/][1/*064*/][1/*065*/] [1/*066*/][1/*067*/][1/*068*/][1/*069*/][1/*070*/] [1/*071*/][1/*072*/][1/*073*/][1/*074*/][1/*075*/] [1/*076*/][1/*077*/][1/*078*/][1/*079*/][1/*080*/] [1/*081*/][1/*082*/][1/*083*/][1/*084*/][1/*085*/] [1/*086*/][1/*087*/][1/*088*/][1/*089*/][1/*090*/] [1/*091*/][1/*092*/][1/*093*/][1/*094*/][1/*095*/] [1/*096*/][1/*097*/][1/*098*/][1/*099*/][1/*100*/] [1/*101*/][1/*102*/][1/*103*/][1/*104*/][1/*105*/] [1/*106*/][1/*107*/][1/*108*/][1/*109*/][1/*110*/] [1/*111*/][1/*112*/][1/*113*/][1/*114*/][1/*115*/] [1/*116*/][1/*117*/][1/*118*/][1/*119*/][1/*120*/] [1/*121*/][1/*122*/][1/*123*/][1/*124*/][1/*125*/] [1/*126*/][1/*127*/][1/*128*/][1/*129*/][1/*130*/] [1/*131*/][1/*132*/][1/*133*/][1/*134*/][1/*135*/] [1/*136*/][1/*137*/][1/*138*/][1/*139*/][1/*140*/] [1/*141*/][1/*142*/][1/*143*/][1/*144*/][1/*145*/] [1/*146*/][1/*147*/][1/*148*/][1/*149*/][1/*150*/] [1/*151*/][1/*152*/][1/*153*/][1/*154*/][1/*155*/] [1/*156*/][1/*157*/][1/*158*/][1/*159*/][1/*160*/] [1/*161*/][1/*162*/][1/*163*/][1/*164*/][1/*165*/] [1/*166*/][1/*167*/][1/*168*/][1/*169*/][1/*170*/] [1/*171*/][1/*172*/][1/*173*/][1/*174*/][1/*175*/] [1/*176*/][1/*177*/][1/*178*/][1/*179*/][1/*180*/] [1/*181*/][1/*182*/][1/*183*/][1/*184*/][1/*185*/] [1/*186*/][1/*187*/][1/*188*/][1/*189*/][1/*190*/] [1/*191*/][1/*192*/][1/*193*/][1/*194*/][1/*195*/] [1/*196*/][1/*197*/][1/*198*/][1/*199*/][1/*200*/] [1/*201*/][1/*202*/][1/*203*/][1/*204*/][1/*205*/] [1/*206*/][1/*207*/][1/*208*/][1/*209*/][1/*210*/] [1/*211*/][1/*212*/][1/*213*/][1/*214*/][1/*215*/] [1/*216*/][1/*217*/][1/*218*/][1/*219*/][1/*220*/] [1/*221*/][1/*222*/][1/*223*/][1/*224*/][1/*225*/] [1/*226*/][1/*227*/][1/*228*/][1/*229*/][1/*230*/] [1/*231*/][1/*232*/][1/*233*/][1/*234*/][1/*235*/] [1/*236*/][1/*237*/][1/*238*/][1/*239*/][1/*240*/] [1/*241*/][1/*242*/][1/*243*/][1/*244*/][1/*245*/] [1/*246*/][1/*247*/][1/*248*/][1/*249*/][1/*250*/] [1/*251*/][1/*252*/][1/*253*/][1/*254*/][1/*255*/] []; }
4,989
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Test255.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4917091/Test255.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 4917091 * @summary javac rejects array over 128 in length */ public class Test255 { public static void main(String... args) { // allocating an array with 255 dimensions is allowed Object expected = (Object)new Object [1/*001*/][1/*002*/][1/*003*/][1/*004*/][1/*005*/] [1/*006*/][1/*007*/][1/*008*/][1/*009*/][1/*010*/] [1/*011*/][1/*012*/][1/*013*/][1/*014*/][1/*015*/] [1/*016*/][1/*017*/][1/*018*/][1/*019*/][1/*020*/] [1/*021*/][1/*022*/][1/*023*/][1/*024*/][1/*025*/] [1/*026*/][1/*027*/][1/*028*/][1/*029*/][1/*030*/] [1/*031*/][1/*032*/][1/*033*/][1/*034*/][1/*035*/] [1/*036*/][1/*037*/][1/*038*/][1/*039*/][1/*040*/] [1/*041*/][1/*042*/][1/*043*/][1/*044*/][1/*045*/] [1/*046*/][1/*047*/][1/*048*/][1/*049*/][1/*050*/] [1/*051*/][1/*052*/][1/*053*/][1/*054*/][1/*055*/] [1/*056*/][1/*057*/][1/*058*/][1/*059*/][1/*060*/] [1/*061*/][1/*062*/][1/*063*/][1/*064*/][1/*065*/] [1/*066*/][1/*067*/][1/*068*/][1/*069*/][1/*070*/] [1/*071*/][1/*072*/][1/*073*/][1/*074*/][1/*075*/] [1/*076*/][1/*077*/][1/*078*/][1/*079*/][1/*080*/] [1/*081*/][1/*082*/][1/*083*/][1/*084*/][1/*085*/] [1/*086*/][1/*087*/][1/*088*/][1/*089*/][1/*090*/] [1/*091*/][1/*092*/][1/*093*/][1/*094*/][1/*095*/] [1/*096*/][1/*097*/][1/*098*/][1/*099*/][1/*100*/] [1/*101*/][1/*102*/][1/*103*/][1/*104*/][1/*105*/] [1/*106*/][1/*107*/][1/*108*/][1/*109*/][1/*110*/] [1/*111*/][1/*112*/][1/*113*/][1/*114*/][1/*115*/] [1/*116*/][1/*117*/][1/*118*/][1/*119*/][1/*120*/] [1/*121*/][1/*122*/][1/*123*/][1/*124*/][1/*125*/] [1/*126*/][1/*127*/][1/*128*/][1/*129*/][1/*130*/] [1/*131*/][1/*132*/][1/*133*/][1/*134*/][1/*135*/] [1/*136*/][1/*137*/][1/*138*/][1/*139*/][1/*140*/] [1/*141*/][1/*142*/][1/*143*/][1/*144*/][1/*145*/] [1/*146*/][1/*147*/][1/*148*/][1/*149*/][1/*150*/] [1/*151*/][1/*152*/][1/*153*/][1/*154*/][1/*155*/] [1/*156*/][1/*157*/][1/*158*/][1/*159*/][1/*160*/] [1/*161*/][1/*162*/][1/*163*/][1/*164*/][1/*165*/] [1/*166*/][1/*167*/][1/*168*/][1/*169*/][1/*170*/] [1/*171*/][1/*172*/][1/*173*/][1/*174*/][1/*175*/] [1/*176*/][1/*177*/][1/*178*/][1/*179*/][1/*180*/] [1/*181*/][1/*182*/][1/*183*/][1/*184*/][1/*185*/] [1/*186*/][1/*187*/][1/*188*/][1/*189*/][1/*190*/] [1/*191*/][1/*192*/][1/*193*/][1/*194*/][1/*195*/] [1/*196*/][1/*197*/][1/*198*/][1/*199*/][1/*200*/] [1/*201*/][1/*202*/][1/*203*/][1/*204*/][1/*205*/] [1/*206*/][1/*207*/][1/*208*/][1/*209*/][1/*210*/] [1/*211*/][1/*212*/][1/*213*/][1/*214*/][1/*215*/] [1/*216*/][1/*217*/][1/*218*/][1/*219*/][1/*220*/] [1/*221*/][1/*222*/][1/*223*/][1/*224*/][1/*225*/] [1/*226*/][1/*227*/][1/*228*/][1/*229*/][1/*230*/] [1/*231*/][1/*232*/][1/*233*/][1/*234*/][1/*235*/] [1/*236*/][1/*237*/][1/*238*/][1/*239*/][1/*240*/] [1/*241*/][1/*242*/][1/*243*/][1/*244*/][1/*245*/] [1/*246*/][1/*247*/][1/*248*/][1/*249*/][1/*250*/] [1/*251*/][1/*252*/][1/*253*/][1/*254*/][1/*255*/]; } }
4,755
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Test256a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/4917091/Test256a.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 4917091 * @summary javac rejects array over 128 in length * @compile/fail/ref=Test256a.out -XDrawDiagnostics Test256a.java */ public class Test256a { // allocating an array with more than 255 dimensions is not allowed static Object expected = (Object)new Object [1/*001*/][1/*002*/][1/*003*/][1/*004*/][1/*005*/] [1/*006*/][1/*007*/][1/*008*/][1/*009*/][1/*010*/] [1/*011*/][1/*012*/][1/*013*/][1/*014*/][1/*015*/] [1/*016*/][1/*017*/][1/*018*/][1/*019*/][1/*020*/] [1/*021*/][1/*022*/][1/*023*/][1/*024*/][1/*025*/] [1/*026*/][1/*027*/][1/*028*/][1/*029*/][1/*030*/] [1/*031*/][1/*032*/][1/*033*/][1/*034*/][1/*035*/] [1/*036*/][1/*037*/][1/*038*/][1/*039*/][1/*040*/] [1/*041*/][1/*042*/][1/*043*/][1/*044*/][1/*045*/] [1/*046*/][1/*047*/][1/*048*/][1/*049*/][1/*050*/] [1/*051*/][1/*052*/][1/*053*/][1/*054*/][1/*055*/] [1/*056*/][1/*057*/][1/*058*/][1/*059*/][1/*060*/] [1/*061*/][1/*062*/][1/*063*/][1/*064*/][1/*065*/] [1/*066*/][1/*067*/][1/*068*/][1/*069*/][1/*070*/] [1/*071*/][1/*072*/][1/*073*/][1/*074*/][1/*075*/] [1/*076*/][1/*077*/][1/*078*/][1/*079*/][1/*080*/] [1/*081*/][1/*082*/][1/*083*/][1/*084*/][1/*085*/] [1/*086*/][1/*087*/][1/*088*/][1/*089*/][1/*090*/] [1/*091*/][1/*092*/][1/*093*/][1/*094*/][1/*095*/] [1/*096*/][1/*097*/][1/*098*/][1/*099*/][1/*100*/] [1/*101*/][1/*102*/][1/*103*/][1/*104*/][1/*105*/] [1/*106*/][1/*107*/][1/*108*/][1/*109*/][1/*110*/] [1/*111*/][1/*112*/][1/*113*/][1/*114*/][1/*115*/] [1/*116*/][1/*117*/][1/*118*/][1/*119*/][1/*120*/] [1/*121*/][1/*122*/][1/*123*/][1/*124*/][1/*125*/] [1/*126*/][1/*127*/][1/*128*/][1/*129*/][1/*130*/] [1/*131*/][1/*132*/][1/*133*/][1/*134*/][1/*135*/] [1/*136*/][1/*137*/][1/*138*/][1/*139*/][1/*140*/] [1/*141*/][1/*142*/][1/*143*/][1/*144*/][1/*145*/] [1/*146*/][1/*147*/][1/*148*/][1/*149*/][1/*150*/] [1/*151*/][1/*152*/][1/*153*/][1/*154*/][1/*155*/] [1/*156*/][1/*157*/][1/*158*/][1/*159*/][1/*160*/] [1/*161*/][1/*162*/][1/*163*/][1/*164*/][1/*165*/] [1/*166*/][1/*167*/][1/*168*/][1/*169*/][1/*170*/] [1/*171*/][1/*172*/][1/*173*/][1/*174*/][1/*175*/] [1/*176*/][1/*177*/][1/*178*/][1/*179*/][1/*180*/] [1/*181*/][1/*182*/][1/*183*/][1/*184*/][1/*185*/] [1/*186*/][1/*187*/][1/*188*/][1/*189*/][1/*190*/] [1/*191*/][1/*192*/][1/*193*/][1/*194*/][1/*195*/] [1/*196*/][1/*197*/][1/*198*/][1/*199*/][1/*200*/] [1/*201*/][1/*202*/][1/*203*/][1/*204*/][1/*205*/] [1/*206*/][1/*207*/][1/*208*/][1/*209*/][1/*210*/] [1/*211*/][1/*212*/][1/*213*/][1/*214*/][1/*215*/] [1/*216*/][1/*217*/][1/*218*/][1/*219*/][1/*220*/] [1/*221*/][1/*222*/][1/*223*/][1/*224*/][1/*225*/] [1/*226*/][1/*227*/][1/*228*/][1/*229*/][1/*230*/] [1/*231*/][1/*232*/][1/*233*/][1/*234*/][1/*235*/] [1/*236*/][1/*237*/][1/*238*/][1/*239*/][1/*240*/] [1/*241*/][1/*242*/][1/*243*/][1/*244*/][1/*245*/] [1/*246*/][1/*247*/][1/*248*/][1/*249*/][1/*250*/] [1/*251*/][1/*252*/][1/*253*/][1/*254*/][1/*255*/] [1/*256*/]; }
4,817
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6457284.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6457284/T6457284.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 6457284 * @summary Internationalize "unnamed package" when the term is used in diagnostics * @author Peter von der Ah\u00e9 */ import java.io.IOException; import java.net.URI; import javax.lang.model.element.Element; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.JavacMessages; import javax.tools.*; public class T6457284 { static class MyFileObject extends SimpleJavaFileObject { public MyFileObject() { super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); } public CharSequence getCharContent(boolean ignoreEncodingErrors) { return "class Test {}"; } } public static void main(String[] args) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, null, null, null, null, List.of(new MyFileObject())); MyMessages.preRegister(task.getContext()); task.parse(); for (Element e : task.analyze()) { if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package")) throw new AssertionError(e.getEnclosingElement()); System.out.println("OK: " + e.getEnclosingElement()); return; } throw new AssertionError("No top-level classes!"); } static class MyMessages extends JavacMessages { static void preRegister(Context context) { context.put(messagesKey, new MyMessages()); } MyMessages() { super("com.sun.tools.javac.resources.compiler"); } public String getLocalizedString(String key, Object... args) { if (key.equals("compiler.misc.unnamed.package")) return key; else return super.getLocalizedString(key, args); } } }
3,105
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6410653.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/6410653/T6410653.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 6410653 6401277 * @summary REGRESSION: javac crashes if -d or -s argument is a file * @author Peter von der Ah\u00e9 */ import java.lang.reflect.Method; import java.io.File; import java.io.ByteArrayOutputStream; import javax.tools.*; public class T6410653 { public static void main(String... args) throws Exception { File testSrc = new File(System.getProperty("test.src")); String source = new File(testSrc, "T6410653.java").getPath(); ClassLoader cl = ToolProvider.getSystemToolClassLoader(); Tool compiler = ToolProvider.getSystemJavaCompiler(); Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl); Method useRawMessages = main.getMethod("useRawMessages", boolean.class); useRawMessages.invoke(null, true); ByteArrayOutputStream out = new ByteArrayOutputStream(); compiler.run(null, null, out, "-d", source, source); useRawMessages.invoke(null, false); if (!out.toString().equals(String.format("%s%n%s%n", "javac: javac.err.file.not.directory", "javac.msg.usage"))) { throw new AssertionError(out); } System.out.println("Test PASSED. Running javac again to see localized output:"); compiler.run(null, null, System.out, "-d", source, source); } }
2,483
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/ImportPackagePrivateInner/Dummy.java
/* * Copyright (c) 2000, 2001, 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 4086815 * @summary Package accessible inner classes were not visible to * import directive in same package. * @author turnidge * * @clean foo.Accessee foo.Accessee$Inside * @compile -classpath . foo/Accessor.java foo/Accessee.java */ public class Dummy {}
1,351
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Accessee.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportPackagePrivateInner/foo/Accessee.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 class Accessee { class Inside {} }
1,118
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
Accessor.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ImportPackagePrivateInner/foo/Accessor.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.Accessee.Inside; public class Accessor { }
1,127
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
PvtMbrsNotInherit1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/inheritAccess/PvtMbrsNotInherit1.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 4240480 * @summary Private members should not be inherited from superclasses. * * @run compile PvtMbrsNotInherit1.java * @run main PvtMbrsNotInherit1 */ public class PvtMbrsNotInherit1 extends OtherClass { public static void main(String args[]) { java.lang.Long.toString(0); } } class OtherClass { private int java; }
1,420
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ExtDirTest_2.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ExtDirs/ExtDirTest_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. */ import pkg1.*; import pkg2.*; public class ExtDirTest_2 { ExtDirTestClass1 x; ExtDirTestClass2 y; }
1,157
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ExtDirTest_3.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ExtDirs/ExtDirTest_3.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. */ import pkg1.*; import pkg2.*; public class ExtDirTest_3 { ExtDirTestClass1 x; ExtDirTestClass2 y; }
1,157
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
ExtDirTest_1.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/ExtDirs/ExtDirTest_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. */ import pkg1.*; public class ExtDirTest_1 { ExtDirTestClass1 x; }
1,120
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/6668794/badSource/Test.java
/* * @test /nodynamiccopyight/ * @bug 6668794 6668796 * @summary javac puts localized text in raw diagnostics * bad diagnostic "bad class file" given for source files * @compile/fail/ref=Test.out -XDrawDiagnostics Test.java */ class Test { p.A a; }
265
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/6668794/badSource/p/A.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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 q; class A { }
1,232
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/6668794/badClass/A.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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 q; class A { }
1,232
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/6668794/badClass/B.java
/* * /nodynamiccopyright/ */ class B { p.A a; }
55
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/6668794/badClass/Test.java
/* * Copyright (c) 2008, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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 6668794 6668796 * @summary javac puts localized text in raw diagnostics * bad diagnostic "bad class file" given for source files */ import java.io.*; import java.util.*; import javax.tools.*; public class Test { public static void main(String[] args) throws Exception { new Test().run(); } void run() throws Exception { // compile q.A then move it to p.A compile("A.java"); File p = new File("p"); p.mkdirs(); new File("q/A.class").renameTo(new File("p/A.class")); // compile B against p.A String[] out = compile("B.java"); if (out.length == 0) throw new Error("no diagnostics generated"); String expected = "B.java:6:6: compiler.err.cant.access: p.A, " + "(compiler.misc.bad.class.file.header: A.class, " + "(compiler.misc.class.file.wrong.class: q.A))"; if (!out[0].equals(expected)) { System.err.println("expected: " + expected); System.err.println(" found: " + out[0]); throw new Error("test failed"); } } String[] compile(String file) { String[] options = { "-XDrawDiagnostics", "-d", ".", "-classpath", ".", new File(testSrc, file).getPath() }; System.err.println("compile: " + Arrays.asList(options)); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); int rc = com.sun.tools.javac.Main.compile(options, out); out.close(); String outText = sw.toString(); System.err.println(outText); return sw.toString().split("[\\r\\n]+"); } File testSrc = new File(System.getProperty("test.src", ".")); }
3,005
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
JavacTestingAbstractProcessor.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lib/JavacTestingAbstractProcessor.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. */ import java.util.*; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; import javax.lang.model.util.*; /** * An abstract annotation processor tailored to javac regression testing. */ public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { private static final Set<String> allAnnotations; static { Set<String> tmp = new HashSet<>(); tmp.add("*"); allAnnotations = Collections.unmodifiableSet(tmp); } protected Elements eltUtils; protected Elements elements; protected Types typeUtils; protected Types types; protected Filer filer; protected Messager messager; protected Map<String, String> options; /** * Constructor for subclasses to call. */ protected JavacTestingAbstractProcessor() { super(); } /** * Return the latest source version. Unless this method is * overridden, an {@code IllegalStateException} will be thrown if a * subclass has a {@code SupportedSourceVersion} annotation. */ @Override public SourceVersion getSupportedSourceVersion() { SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class); if (ssv != null) throw new IllegalStateException("SupportedSourceVersion annotation not supported here."); return SourceVersion.latest(); } /** * If the processor class is annotated with {@link * SupportedAnnotationTypes}, return an unmodifiable set with the * same set of strings as the annotation. If the class is not so * annotated, a one-element set containing {@code "*"} is returned * to indicate all annotations are processed. * * @return the names of the annotation types supported by this * processor, or an empty set if none */ @Override public Set<String> getSupportedAnnotationTypes() { SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class); if (sat != null) return super.getSupportedAnnotationTypes(); else return allAnnotations; } @Override public void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); elements = eltUtils = processingEnv.getElementUtils(); types = typeUtils = processingEnv.getTypeUtils(); filer = processingEnv.getFiler(); messager = processingEnv.getMessager(); options = processingEnv.getOptions(); } }
3,610
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CompileFail.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/lib/CompileFail.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. */ import java.io.*; import java.util.*; /* * Utility class to emulate jtreg @compile/fail, but also checking the specific * exit code, given as the first arg. */ public class CompileFail { public static void main(String... args) { if (args.length < 2) throw new IllegalArgumentException("insufficient args"); int expected_rc = getReturnCode(args[0]); List<String> javacArgs = new ArrayList<>(); javacArgs.addAll(Arrays.asList( "-bootclasspath", System.getProperty("sun.boot.class.path"), "-d", "." )); File testSrc = new File(System.getProperty("test.src")); for (int i = 1; i < args.length; i++) { String arg = args[i]; if (arg.endsWith(".java")) javacArgs.add(new File(testSrc, arg).getPath()); else javacArgs.add(arg); } int rc = com.sun.tools.javac.Main.compile( javacArgs.toArray(new String[javacArgs.size()])); if (rc != expected_rc) throw new Error("unexpected exit code: " + rc + ", expected: " + expected_rc); } static int getReturnCode(String name) { switch (name) { case "OK": return EXIT_OK; case "ERROR": return EXIT_ERROR; case "CMDERR": return EXIT_CMDERR; case "SYSERR": return EXIT_SYSERR; case "ABNORMAL": return EXIT_ABNORMAL; default: throw new IllegalArgumentException(name); } } // The following is cut-n-paste from com.sun.tools.javac.main.Main static final int EXIT_OK = 0, // Compilation completed with no errors. EXIT_ERROR = 1, // Completed but reported errors. EXIT_CMDERR = 2, // Bad command-line arguments EXIT_SYSERR = 3, // System error or resource exhaustion. EXIT_ABNORMAL = 4; // Compiler terminated abnormally }
3,111
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CrossPackageImplB.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/crossPackageImpl/CrossPackageImplB.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 b; public abstract class CrossPackageImplB extends a.CrossPackageImplA { }
1,136
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
CrossPackageImplA.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/crossPackageImpl/CrossPackageImplA.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 4362349 * @summary Cannot override abstract method in same package * @author gafter * * @compile CrossPackageImplA.java CrossPackageImplB.java */ package a; public abstract class CrossPackageImplA { public static void main(String[] args) { CrossPackageImplA a = new CrossPackageImplC(); System.out.println(a.message()); } abstract String message(); } class CrossPackageImplC extends b.CrossPackageImplB { String message() { return "Hello, world"; } }
1,564
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
BoxedArray.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/cast/BoxedArray.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 5014309 * @summary REGRESSION: compiler allows cast from Integer[] to int[] * @author gafter * * @compile/fail BoxedArray.java */ public class BoxedArray { int[] a2; void f(Integer[] a1) { a2 = (int[]) a1; } }
1,308
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6548436a.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/cast/6548436/T6548436a.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 6548436 * @summary Incorrect inconvertible types error * @author Maurizio Cimadamore * * @compile T6548436a.java */ public class T6548436a { static class Base<E extends Comparable<E>> {} static void test(Base<?> je) { Object o = (Base<Integer>)je; } }
1,352
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6548436c.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/cast/6548436/T6548436c.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 6548436 * @summary Incorrect inconvertible types error * @author Maurizio Cimadamore * * @compile T6548436c.java */ public class T6548436c { interface A<T extends A<? super T>> { } interface B extends A<B> { } static void test(A<?> a) { Object o = (B)a; } }
1,363
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z
T6548436b.java
/FileExtraction/Java_unseen/openjdk-mirror_jdk7u-langtools/test/tools/javac/cast/6548436/T6548436b.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 6548436 * @summary Incorrect inconvertible types error * @author Maurizio Cimadamore * * @compile T6548436b.java */ public class T6548436b { enum E { } static void test(Enum<?> o) { Object e = (E)o; } }
1,303
Java
.java
openjdk-mirror/jdk7u-langtools
9
3
0
2012-05-07T19:45:34Z
2012-05-08T17:47:06Z