undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,225 @@
/*
* Copyright (c) 2009, 2024, 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 4241573
* @summary SourceFile attribute includes full path
*/
import java.lang.classfile.*;
import java.lang.classfile.Attributes;
import java.lang.classfile.attribute.*;
import java.io.*;
import java.util.*;
import java.util.jar.*;
public class T4241573 {
public static void main(String... args) throws Exception {
new T4241573().run();
}
public void run() throws Exception {
// Selection of files to be compiled
File absJar = createJar(new File("abs.jar").getAbsoluteFile(), "j.A");
File relJar = createJar(new File("rel.jar"), "j.R");
File absDir = createDir(new File("abs.dir").getAbsoluteFile(), "d.A");
File relDir = createDir(new File("rel.dir"), "d.R");
File absTestFile = writeFile(new File("AbsTest.java").getAbsoluteFile(), "class AbsTest { class Inner { } }");
File relTestFile = writeFile(new File("RelTest.java"), "class RelTest { class Inner { } }");
File relTest2File = writeFile(new File("p/RelTest2.java"), "package p; class RelTest2 { class Inner { } }");
// This next class references other classes that will be found on the source path
// and which will therefore need to be compiled as well.
File mainFile = writeFile(new File("Main.java"),
"class Main { j.A ja; j.R jr; d.A da; d.R dr; }" +
"");
String sourcePath = createPath(absJar, relJar, absDir, relDir);
File outDir = new File("classes");
outDir.mkdirs();
String[] args = {
"-sourcepath", sourcePath,
"-d", outDir.getPath(),
absTestFile.getPath(),
relTestFile.getPath(),
relTest2File.getPath(),
mainFile.getPath(),
};
System.err.println("compile: " + Arrays.asList(args));
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
int rc = com.sun.tools.javac.Main.compile(args, pw);
pw.close();
if (rc != 0) {
System.err.println(sw.toString());
throw new Exception("unexpected exit from javac: " + rc);
}
Set<File> expect = getFiles(outDir,
"d/A.class", "d/A$Inner.class",
"d/R.class", "d/R$Inner.class",
"j/A.class", "j/A$Inner.class",
"j/R.class", "j/R$Inner.class",
"AbsTest.class", "AbsTest$Inner.class",
"RelTest.class", "RelTest$Inner.class",
"p/RelTest2.class", "p/RelTest2$Inner.class",
"Main.class" );
Set<File> found = findFiles(outDir);
if (!found.equals(expect)) {
if (found.containsAll(expect))
throw new Exception("unexpected files found: " + diff(found, expect));
else if (expect.containsAll(found))
throw new Exception("expected files not found: " + diff(expect, found));
}
for (File f: found)
verifySourceFileAttribute(f);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
/** Check the SourceFileAttribute is the simple name of the original source file. */
void verifySourceFileAttribute(File f) {
System.err.println("verify: " + f);
try {
ClassModel cf = ClassFile.of().parse(f.toPath());
SourceFileAttribute sfa = cf.findAttribute(Attributes.sourceFile()).orElseThrow();
String found = sfa.sourceFile().stringValue();
String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
if (!expect.equals(found)) {
error("bad value found: " + found + ", expected: " + expect);
}
} catch (Exception e) {
error("error reading " + f +": " + e);
}
}
/** Create a directory containing one or more files. */
File createDir(File dir, String... entries) throws Exception {
if (!dir.mkdirs())
throw new Exception("cannot create directories " + dir);
for (String e: entries) {
writeFile(new File(dir, getPathForDirEntry(e)), getBodyForEntry(e));
}
return dir;
}
/** Create a jar file containing one or more entries. */
File createJar(File jar, String... entries) throws IOException {
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar))) {
for (String e: entries) {
jos.putNextEntry(new JarEntry(getPathForZipEntry(e)));
jos.write(getBodyForEntry(e).getBytes());
}
}
return jar;
}
/** Return the path for an entry given to createDir */
String getPathForDirEntry(String e) {
return e.replace(".", File.separator) + ".java";
}
/** Return the path for an entry given to createJar. */
String getPathForZipEntry(String e) {
return e.replace(".", "/") + ".java";
}
/** Return the body text for an entry given to createDir or createJar. */
String getBodyForEntry(String e) {
int sep = e.lastIndexOf(".");
String pkgName = e.substring(0, sep);
String className = e.substring(sep + 1);
return "package " + pkgName + "; public class " + className + "{ class Inner { } }";
}
/** Write a file containing the given string. Parent directories are
* created as needed. */
File writeFile(File f, String s) throws IOException {
if (f.getParentFile() != null)
f.getParentFile().mkdirs();
FileWriter out = new FileWriter(f);
try {
out.write(s);
} finally {
out.close();
}
return f;
}
/** Create a path value from a list of directories and jar files. */
String createPath(File... files) {
StringBuilder sb = new StringBuilder();
for (File f: files) {
if (sb.length() > 0)
sb.append(File.pathSeparatorChar);
sb.append(f.getPath());
}
return sb.toString();
}
/** Create a set of files from a base directory and a set of relative paths. */
Set<File> getFiles(File dir, String... paths) {
Set<File> files = new LinkedHashSet<File>();
for (String p: paths)
files.add(new File(dir, p));
return files;
}
/** Find all the files in a directory and its subdirectories. */
Set<File> findFiles(File dir) {
Set<File> files = new LinkedHashSet<File>();
findFiles(dir, files);
return files;
}
// where
void findFiles(File dir, Set<File> files) {
for (File f: dir.listFiles()) {
if (f.isDirectory())
findFiles(f, files);
else
files.add(f);
}
}
/** Return the difference of two sets, a - b. */
<T> Set<T> diff(Set<T> a, Set<T> b) {
if (b.isEmpty())
return a;
Set<T> result = new LinkedHashSet<T>(a);
result.removeAll(b);
return result;
}
/** Report an error. */
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}

View file

@ -0,0 +1,116 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4846262
* @summary check that javac operates correctly in EBCDIC locale
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.jdeps/com.sun.tools.javap
* @build toolbox.ToolBox
* @run main CheckEBCDICLocaleTest
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import toolbox.ToolBox;
public class CheckEBCDICLocaleTest {
private static final String TestSrc =
"public class Test {\n" +
" public void test() {\n" +
" abcdefg\n" +
" }\n" +
"}";
private static final String TestOutTemplate =
"output%1$sTest.java:3: error: not a statement\n" +
" abcdefg\n" +
" ^\n" +
"output%1$sTest.java:3: error: ';' expected\n" +
" abcdefg\n" +
" ^\n" +
"2 errors\n";
public static void main(String[] args) throws Exception {
new CheckEBCDICLocaleTest().test();
}
public void test() throws Exception {
ToolBox tb = new ToolBox();
tb.writeFile("Test.java", TestSrc);
tb.createDirectories("output");
Charset ebcdic = Charset.forName("IBM1047");
Native2Ascii n2a = new Native2Ascii(ebcdic);
n2a.asciiToNative(Paths.get("Test.java"), Paths.get("output", "Test.java"));
// Use -encoding to specify the encoding with which to read source files
// Use a suitable configured output stream for javac diagnostics
int rc;
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Test.tmp"), ebcdic))) {
String[] args = { "-encoding", ebcdic.name(), "output/Test.java" };
rc = com.sun.tools.javac.Main.compile(args, out);
if (rc != 1)
throw new Exception("unexpected exit from javac: " + rc);
}
n2a.nativeToAscii(Paths.get("Test.tmp"), Paths.get("Test.out"));
List<String> expectLines = Arrays.asList(
String.format(TestOutTemplate, File.separator).split("\n"));
List<String> actualLines = Files.readAllLines(Paths.get("Test.out"));
try {
tb.checkEqual(expectLines, actualLines);
} catch (Throwable tt) {
PrintStream out = tb.out;
out.println("Output mismatch:");
out.println("Expected output:");
for (String s: expectLines) {
out.println(s);
}
out.println();
out.println("Actual output:");
for (String s : actualLines) {
out.println(s);
}
out.println();
throw tt;
}
}
}

View file

@ -0,0 +1,213 @@
/*
* Copyright (c) 2015, 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FilterReader;
import java.io.FilterWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import static java.nio.charset.StandardCharsets.*;
/**
* Simple utility to convert from native encoding file to ascii or reverse
* including \udddd Unicode notation.
*/
public class Native2Ascii {
final Charset cs;
final CharsetEncoder encoder;
public Native2Ascii(Charset cs) {
this.cs = cs;
this.encoder = cs.newEncoder();
}
/**
* ASCII to Native conversion
*/
public void asciiToNative(Path infile, Path outfile) throws IOException {
try (BufferedReader in = Files.newBufferedReader(infile, US_ASCII);
BufferedReader reader = new BufferedReader(new A2NFilter(in));
BufferedWriter writer = Files.newBufferedWriter(outfile, cs)) {
String line;
while ((line = reader.readLine()) != null) {
writer.write(line.toCharArray());
writer.newLine();
}
}
}
/**
* Native to ASCII conversion
*/
public void nativeToAscii(Path infile, Path outfile) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(infile, cs);
BufferedWriter out = Files.newBufferedWriter(outfile, US_ASCII);
BufferedWriter writer = new BufferedWriter(new N2AFilter(out))) {
String line;
while ((line = reader.readLine()) != null) {
writer.write(line.toCharArray());
writer.newLine();
}
}
}
// A copy of native2ascii N2AFilter
class N2AFilter extends FilterWriter {
public N2AFilter(Writer out) { super(out); }
public void write(char b) throws IOException {
char[] buf = new char[1];
buf[0] = b;
write(buf, 0, 1);
}
public void write(char[] buf, int off, int len) throws IOException {
for (int i = 0; i < len; i++) {
if ((buf[i] > '\u007f')) {
// write \udddd
out.write('\\');
out.write('u');
String hex = Integer.toHexString(buf[i]);
StringBuilder hex4 = new StringBuilder(hex);
hex4.reverse();
int length = 4 - hex4.length();
for (int j = 0; j < length; j++) {
hex4.append('0');
}
for (int j = 0; j < 4; j++) {
out.write(hex4.charAt(3 - j));
}
} else
out.write(buf[i]);
}
}
}
// A copy of native2ascii A2NFilter
class A2NFilter extends FilterReader {
// maintain a trailing buffer to hold any incompleted
// unicode escaped sequences
private char[] trailChars = null;
public A2NFilter(Reader in) {
super(in);
}
public int read(char[] buf, int off, int len) throws IOException {
int numChars = 0; // how many characters have been read
int retChars = 0; // how many characters we'll return
char[] cBuf = new char[len];
int cOffset = 0; // offset at which we'll start reading
boolean eof = false;
// copy trailing chars from previous invocation to input buffer
if (trailChars != null) {
for (int i = 0; i < trailChars.length; i++)
cBuf[i] = trailChars[i];
numChars = trailChars.length;
trailChars = null;
}
int n = in.read(cBuf, numChars, len - numChars);
if (n < 0) {
eof = true;
if (numChars == 0)
return -1; // EOF;
} else {
numChars += n;
}
for (int i = 0; i < numChars; ) {
char c = cBuf[i++];
if (c != '\\' || (eof && numChars <= 5)) {
// Not a backslash, so copy and continue
// Always pass non backslash chars straight thru
// for regular encoding. If backslash occurs in
// input stream at the final 5 chars then don't
// attempt to read-ahead and de-escape since these
// are literal occurrences of U+005C which need to
// be encoded verbatim in the target encoding.
buf[retChars++] = c;
continue;
}
int remaining = numChars - i;
if (remaining < 5) {
// Might be the first character of a unicode escape, but we
// don't have enough characters to tell, so save it and finish
trailChars = new char[1 + remaining];
trailChars[0] = c;
for (int j = 0; j < remaining; j++)
trailChars[1 + j] = cBuf[i + j];
break;
}
// At this point we have at least five characters remaining
c = cBuf[i++];
if (c != 'u') {
// Not a unicode escape, so copy and continue
buf[retChars++] = '\\';
buf[retChars++] = c;
continue;
}
// The next four characters are the hex part of a unicode escape
char rc = 0;
boolean isUE = true;
try {
rc = (char) Integer.parseInt(new String(cBuf, i, 4), 16);
} catch (NumberFormatException x) {
isUE = false;
}
if (isUE && encoder.canEncode(rc)) {
// We'll be able to convert this
buf[retChars++] = rc;
i += 4; // Align beyond the current uXXXX sequence
} else {
// We won't, so just retain the original sequence
buf[retChars++] = '\\';
buf[retChars++] = 'u';
continue;
}
}
return retChars;
}
public int read() throws IOException {
char[] buf = new char[1];
if (read(buf, 0, 1) == -1)
return -1;
else
return (int) buf[0];
}
}
}

View file

@ -0,0 +1,11 @@
T4880220.java:20:27: compiler.warn.static.not.qualified.by.type: kindname.method, T4880220.C
T4880220.java:21:27: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:22:27: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:24:29: compiler.warn.static.not.qualified.by.type: kindname.method, T4880220.C
T4880220.java:25:29: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:26:29: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:39:12: compiler.warn.static.not.qualified.by.type2: kindname.method
T4880220.java:40:20: compiler.warn.static.not.qualified.by.type2: kindname.variable
- compiler.err.warnings.and.werror
1 error
8 warnings

View file

@ -0,0 +1,52 @@
/*
* @test /nodynamiccopyright/
* @bug 4880220 8285935
* @summary Add a warning when accessing a static method via an reference
*
* @compile/ref=T4880220.empty.out T4880220.java
* @compile/ref=T4880220.warn.out -XDrawDiagnostics -Xlint:static T4880220.java
* @compile/ref=T4880220.warn.out -XDrawDiagnostics -Xlint:all T4880220.java
* @compile/ref=T4880220.empty.out -XDrawDiagnostics -Xlint:all,-static T4880220.java
* @compile/ref=T4880220.error.out/fail -XDrawDiagnostics -Werror -Xlint:all T4880220.java
*/
public class T4880220 {
void m1() {
int good_1 = C.m();
int good_2 = C.f;
int good_3 = C.x;
C c = new C();
int bad_inst_1 = c.m();
int bad_inst_2 = c.f;
int bad_inst_3 = c.x;
int bad_expr_1 = c().m();
int bad_expr_2 = c().f;
int bad_expr_3 = c().x;
}
void m2() {
Class<?> good_1 = C.class;
Class<?> good_2 = C[].class;
}
void m3() {
var obj = new Object() {
static void foo() {}
static int i = 0;
};
obj.foo();
int j = obj.i;
}
C c() {
return new C();
}
static class C {
static int m() { return 0; }
static int f;
static final int x = 3;
}
}

View file

@ -0,0 +1,9 @@
T4880220.java:20:27: compiler.warn.static.not.qualified.by.type: kindname.method, T4880220.C
T4880220.java:21:27: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:22:27: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:24:29: compiler.warn.static.not.qualified.by.type: kindname.method, T4880220.C
T4880220.java:25:29: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:26:29: compiler.warn.static.not.qualified.by.type: kindname.variable, T4880220.C
T4880220.java:39:12: compiler.warn.static.not.qualified.by.type2: kindname.method
T4880220.java:40:20: compiler.warn.static.not.qualified.by.type2: kindname.variable
8 warnings

View file

@ -0,0 +1,89 @@
/*
* 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*/];
}
}

View file

@ -0,0 +1,65 @@
/*
* @test /nodynamiccopyright/
* @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*/];
}

View file

@ -0,0 +1,2 @@
Test256a.java:10:46: compiler.err.limit.dimensions
1 error

View file

@ -0,0 +1,68 @@
/*
* @test /nodynamiccopyright/
* @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*/]
[];
}

View file

@ -0,0 +1,2 @@
Test256b.java:13:46: compiler.err.limit.dimensions
1 error

View file

@ -0,0 +1,17 @@
/*
* @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 meth() {
f = 1;
}
}

View file

@ -0,0 +1,2 @@
Test.java:15:9: compiler.err.ref.ambiguous: f, kindname.variable, f, p1.A1, kindname.variable, f, p2.A2
1 error

View file

@ -0,0 +1,28 @@
/*
* 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;
}

View file

@ -0,0 +1,28 @@
/*
* 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;
}

View file

@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @bug 7101822 8133616
* @summary Check the when clashing types are imported through an ordinary and static import,
* the compile-time error is properly reported.
* @compile/fail/ref=NonStatic2StaticImportClash.out -XDrawDiagnostics NonStatic2StaticImportClash.java p1/A1.java p2/A2.java
*
*/
import static p1.A1.f;
import p2.A2.f;
public class NonStatic2StaticImportClash {
}

View file

@ -0,0 +1,2 @@
NonStatic2StaticImportClash.java:11:1: compiler.err.already.defined.static.single.import: p1.A1.f
1 error

View file

@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @bug 7101822 8133616
* @summary Check the when clashing types are imported through an ordinary and static import,
* the compile-time error is properly reported.
* @compile/fail/ref=Static2NonStaticImportClash.out -XDrawDiagnostics Static2NonStaticImportClash.java p1/A1.java p2/A2.java
*
*/
import p2.A2.f;
import static p1.A1.f;
public class Static2NonStaticImportClash {
}

View file

@ -0,0 +1,2 @@
Static2NonStaticImportClash.java:11:1: compiler.err.already.defined.single.import: p2.A2.f
1 error

View file

@ -0,0 +1,18 @@
/*
* @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 meth() {
new f();
}
}

View file

@ -0,0 +1,3 @@
Test.java:11:1: compiler.err.already.defined.single.import: p1.A1.f
Test.java:16:13: compiler.err.ref.ambiguous: f, kindname.class, p1.A1.f, p1.A1, kindname.class, p2.A2.f, p2.A2
2 errors

View file

@ -0,0 +1,28 @@
/*
* 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 { };
}

View file

@ -0,0 +1,28 @@
/*
* 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 { };
}

View file

@ -0,0 +1,20 @@
/*
* @test /nodynamiccopyright/
* @bug 5017953
* @summary spurious cascaded diagnostics when name not found
* @compile/fail/ref=T5017953.out -XDrawDiagnostics T5017953.java
*/
class T5017953 {
int f = 0;
void test(int i) {}
{ test(NonExistentClass.f ++);
test(1 + NonExistentClass.f);
test(NonExistentClass.f + 1);
test(NonExistentClass.f + NonExistentClass.f);
test(NonExistentClass.f += 1);
test(f += NonExistentClass.f);
}
}

View file

@ -0,0 +1,8 @@
T5017953.java:13:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:14:18: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:15:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:16:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:16:35: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:17:14: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
T5017953.java:18:19: compiler.err.cant.resolve.location: kindname.variable, NonExistentClass, , , (compiler.misc.location: kindname.class, T5017953, null)
7 errors

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2005, 2013, 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 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java
*/
class Bar implements java.io.Serializable { }

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2005, 2013, 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 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java
*/
class Foo { }

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2005, 2021, 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 6199662 6325201 6726015
* @summary javac: compilation success depends on compilation order
*
* @compile Tree.java TreeScanner.java TreeInfo.java
* @compile TreeInfo.java TreeScanner.java Tree.java
*
* @compile -XDcompilePolicy=bytodo Tree.java TreeScanner.java TreeInfo.java
* @compile -XDcompilePolicy=bytodo TreeInfo.java TreeScanner.java Tree.java
*
* @compile -XDcompilePolicy=byfile Tree.java TreeScanner.java TreeInfo.java
* @compile -XDcompilePolicy=byfile TreeInfo.java TreeScanner.java Tree.java
*
* @compile -XDcompilePolicy=simple Tree.java TreeScanner.java TreeInfo.java
* @compile -XDcompilePolicy=simple TreeInfo.java TreeScanner.java Tree.java
*
* @compile -XDshould-stop.ifError=FLOW -XDshould-stop.ifNoError=FLOW Tree.java TreeScanner.java TreeInfo.java
* @compile -XDshould-stop.ifError=FLOW -XDshould-stop.ifNoError=FLOW TreeInfo.java TreeScanner.java Tree.java
*
* @compile -XDshould-stop.ifError=ATTR -XDshould-stop.ifNoError=ATTR Tree.java TreeScanner.java TreeInfo.java
* @compile -XDshould-stop.ifError=ATTR -XDshould-stop.ifNoError=ATTR TreeInfo.java TreeScanner.java Tree.java
*/
package p;
public abstract class Tree {
/** Visit this tree with a given visitor.
*/
public abstract <E extends Throwable> void accept(Visitor<E> v) throws E;
/** A generic visitor class for trees.
*/
public static abstract class Visitor<E extends Throwable> {
public void visitTree(Tree that) throws E { assert false; }
}
}

View file

@ -0,0 +1,37 @@
/*
* 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 p;
import p.Tree.*;
public class TreeInfo {
public static void declarationFor(final Tree tree) {
class DeclScanner extends TreeScanner<Error> {
public void scan(Tree tree) {
}
}
DeclScanner s = new DeclScanner();
tree.accept(s);
}
}

View file

@ -0,0 +1,34 @@
/*
* 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 p;
import p.Tree.*;
public class TreeScanner<E extends Throwable> extends Visitor<E> {
/** Visitor method: Scan a single node.
*/
public void scan(Tree tree) throws E {
if(tree!=null) tree.accept(this);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6257443 6350124 6357979
* @summary compiler can produce a .class file in some source output modes
*
* @compile package-info.java
* @run main/othervm T6257443 -yes foo/package-info.class
*
* @clean foo.*
*
* @compile -printsource package-info.java
* @run main/othervm T6257443 -no foo/package-info.class
*/
import java.net.URL;
public class T6257443
{
public static void main(String[] args) {
if (args.length != 2)
throw new Error("wrong number of args");
String state = args[0];
String file = args[1];
if (state.equals("-no")) {
URL u = find(file);
if (u != null)
throw new Error("file " + file + " found unexpectedly");
}
else if (state.equals("-yes")) {
URL u = find(file);
if (u == null)
throw new Error("file " + file + " not found");
}
else
throw new Error("bad args");
}
public static URL find(String path) {
return T6257443.class.getClassLoader().getSystemResource(path);
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
@Deprecated
package foo;

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2013, 2017, 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 6302184 6350124 6357979
* @summary javac hidden options that generate source should use the given
* encoding, if available
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build toolbox.ToolBox toolbox.JavacTask
* @run main HiddenOptionsShouldUseGivenEncodingTest
*/
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import toolbox.JavacTask;
import toolbox.ToolBox;
// Original test: test/tools/javac/6302184/T6302184.sh
public class HiddenOptionsShouldUseGivenEncodingTest {
public static void main(String[] args) throws Exception {
String encoding = "iso-8859-1";
Path src = Paths.get("src");
Files.createDirectories(src);
Files.write(src.resolve("T6302184.java"), source, Charset.forName(encoding));
Files.write(src.resolve("T6302184.out"), expect, Charset.forName(encoding));
Path out = Paths.get("out");
Files.createDirectories(out);
ToolBox tb = new ToolBox();
new JavacTask(tb)
.outdir("out")
.options("-encoding", encoding, "-XD-printsource")
.files(src.resolve("T6302184.java"))
.run();
Path path1 = Paths.get("out").resolve("T6302184.java");
List<String> file1 = tb.readAllLines(path1, encoding);
Path path2 = src.resolve("T6302184.out");
List<String> file2 = tb.readAllLines(path2, encoding);
tb.checkEqual(file1, file2);
}
static List<String> source = Arrays.asList(
"class T6302184 {",
" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",
"}"
);
static List<String> expect = Arrays.asList(
"",
"class T6302184 {",
" ",
" T6302184() {",
" super();",
" }",
" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",
"}"
);
}

View file

@ -0,0 +1,40 @@
/*
* @test (important: no SCCS keywords to affect offsets in golden file.) /nodynamiccopyright/
* @bug 6304921
* @compile/fail/ref=T6304921.out -XDcompilePolicy=bytodo -XDrawDiagnostics -Xjcov -Xlint:all -Werror T6304921.java
*/
import java.util.ArrayList;
import java.util.List;
class T6304921 {
void m1(int i) {
switch (i) {
case 1:
i++;
// fallthrough
default:
}
try {
i++;
}
finally {
throw new Error();
// finally does not complete normally
}
}
void m2() {
List<Integer> list = new ArrayList();
}
}
class X {
void m1() {
System.orr.println("abc"); // name not found
}
boolean m2() {
return 123 + true; // bad binary expression
}
}

View file

@ -0,0 +1,7 @@
T6304921.java:29:34: compiler.warn.raw.class.use: java.util.ArrayList, java.util.ArrayList<E>
T6304921.java:29:30: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.ArrayList, java.util.List<java.lang.Integer>
- compiler.err.warnings.and.werror
T6304921.java:35:15: compiler.err.cant.resolve.location: kindname.variable, orr, , , (compiler.misc.location: kindname.class, java.lang.System, null)
T6304921.java:38:20: compiler.err.operator.cant.be.applied.1: +, int, boolean
3 errors
2 warnings

View file

@ -0,0 +1,156 @@
/*
* Copyright (c) 2005, 2025, 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 6304912
* @summary unit test for Log
* @modules jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.parser
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util:+open
* jdk.compiler/com.sun.tools.javac.resources
*/
import java.lang.reflect.Field;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Set;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.parser.Parser;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import com.sun.tools.javac.util.JCDiagnostic.Factory;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
public class TestLog
{
public static void main(String... args) throws Exception {
test(false);
test(true);
}
static void test(boolean genEndPos) throws Exception {
Context context = new Context();
Options options = Options.instance(context);
options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");
Log log = Log.instance(context);
Factory diagnosticFactory = JCDiagnostic.Factory.instance(context);
Field defaultErrorFlagsField =
JCDiagnostic.Factory.class.getDeclaredField("defaultErrorFlags");
defaultErrorFlagsField.setAccessible(true);
Set<DiagnosticFlag> defaultErrorFlags =
(Set<DiagnosticFlag>) defaultErrorFlagsField.get(diagnosticFactory);
defaultErrorFlags.add(DiagnosticFlag.API);
JavacFileManager.preRegister(context);
ParserFactory pfac = ParserFactory.instance(context);
final String text =
"public class Foo {\n"
+ " public static void main(String[] args) {\n"
+ " if (args.length == 0)\n"
+ " System.out.println(\"no args\");\n"
+ " else\n"
+ " System.out.println(args.length + \" args\");\n"
+ " }\n"
+ "}\n";
JavaFileObject fo = new StringJavaFileObject("Foo", text);
log.useSource(fo);
CharSequence cs = fo.getCharContent(true);
Parser parser = pfac.newParser(cs, false, genEndPos, false);
JCTree.JCCompilationUnit tree = parser.parseCompilationUnit();
TreeScanner ts = new LogTester(log);
ts.scan(tree);
check(log.nerrors, 4, "errors");
check(log.nwarnings, 4, "warnings");
}
private static void check(int found, int expected, String name) {
if (found == expected)
System.err.println(found + " " + name + " found, as expected.");
else {
System.err.println("incorrect number of " + name + " found.");
System.err.println("expected: " + expected);
System.err.println(" found: " + found);
throw new IllegalStateException("test failed");
}
}
private static class LogTester extends TreeScanner {
LogTester(Log log) {
this.log = log;
}
public void visitIf(JCTree.JCIf tree) {
JCDiagnostic.DiagnosticPosition nil = null;
// generate dummy messages to exercise the log API
log.error(Errors.NotStmt);
log.error(tree.pos, Errors.NotStmt);
log.error(tree.pos(), Errors.NotStmt);
log.error(nil, Errors.NotStmt);
// some warnings that will be emitted during parsing
log.warning(Warnings.ExtraneousSemicolon);
log.warning(tree.pos, Warnings.ExtraneousSemicolon);
log.warning(tree.pos(), Warnings.ExtraneousSemicolon);
log.warning(nil, Warnings.ExtraneousSemicolon);
}
private Log log;
}
private static class StringJavaFileObject extends SimpleJavaFileObject {
StringJavaFileObject(String name, String text) {
super(URI.create(name), JavaFileObject.Kind.SOURCE);
this.text = text;
}
public CharSequence getCharContent(boolean b) {
return text;
}
public InputStream openInputStream() {
throw new UnsupportedOperationException();
}
public OutputStream openOutputStream() {
throw new UnsupportedOperationException();
}
private String text;
}
}

View file

@ -0,0 +1,12 @@
/*
* @test /nodynamiccopyright/
* @bug 6330920
* @summary Verify that javac doesn't duplicate method error on method with error
* @author Peter von der Ahé
* @compile/fail/ref=T6330920.out -XDrawDiagnostics T6330920.java
*/
public class T6330920 {
public void test(T6330920 x) {}
public void test(T6330920Missing x) {}
}

View file

@ -0,0 +1,2 @@
T6330920.java:11:22: compiler.err.cant.resolve.location: kindname.class, T6330920Missing, , , (compiler.misc.location: kindname.class, T6330920, null)
1 error

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class T1 {
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class T2 {
}

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6330997 7025789 8000961 8188870 8193290
* @summary javac should accept class files with major version of the next release
* @author Wei Tao
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.code
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.util
* @clean T1 T2
* @compile T1.java
* @compile T2.java
* @run main/othervm T6330997
*/
import java.nio.*;
import java.io.*;
import java.nio.channels.*;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.code.ClassFinder.BadClassFile;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.util.Names;
import javax.tools.ToolProvider;
public class T6330997 {
public static void main(String... args) {
increaseMajor("T1.class", 1);
increaseMajor("T2.class", 2);
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
Symtab syms = Symtab.instance(task.getContext());
Names names = Names.instance(task.getContext());
task.ensureEntered();
try {
syms.enterClass(syms.unnamedModule, names.fromString("T1")).complete();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed: unexpected exception while reading class T1");
}
try {
syms.enterClass(syms.unnamedModule, names.fromString("T2")).complete();
} catch (BadClassFile e) {
System.err.println("Passed: expected completion failure " + e.getClass().getName());
return;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed: unexpected exception while reading class T2");
}
throw new RuntimeException("Failed: no error reported");
}
// Increase class file cfile's major version by delta
static void increaseMajor(String cfile, int delta) {
try (RandomAccessFile cls =
new RandomAccessFile(new File(System.getProperty("test.classes", "."), cfile), "rw");
FileChannel fc = cls.getChannel()) {
ByteBuffer rbuf = ByteBuffer.allocate(2);
fc.read(rbuf, 6);
ByteBuffer wbuf = ByteBuffer.allocate(2);
wbuf.putShort(0, (short)(rbuf.getShort(0) + delta));
fc.write(wbuf, 6);
fc.force(false);
} catch (Exception e){
throw new RuntimeException("Failed: unexpected exception");
}
}
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class A {
B b;
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
@SupportedAnnotationTypes("*")
public class Anno extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
//if (!roundEnv.processingOver())
// System.err.println("annotation processing");
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class B { }

View file

@ -0,0 +1,199 @@
/*
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6341866
* @summary Source files loaded from source path are not subject to annotation processing
* @modules java.compiler
* jdk.compiler
* @build Anno T6341866
* @run main T6341866
*/
import java.io.*;
import java.util.*;
import javax.annotation.processing.*;
import javax.tools.*;
/**
* For each of a number of implicit compilation scenarios,
* and for each of a set of annotation processing scenarios,
* verify that a class file is generated, or not, for an
* implicitly compiled source file and that the correct
* warning message is given for implicitly compiled files
* when annotation processing.
*/
public class T6341866 {
static final String testSrc = System.getProperty("test.src", ".");
static final String testClasses = System.getProperty("test.classes", ".");
static final File a_java = new File(testSrc, "A.java");
static final File a_class = new File("A.class");
static final File b_java = new File(testSrc, "B.java");
static final File b_class = new File("B.class");
static final File processorServices = services(Processor.class);
enum ImplicitType {
NONE(null), // don't use implicit compilation
OPT_UNSET(null), // implicit compilation, but no -implicit option
OPT_NONE("-implicit:none"), // implicit compilation with -implicit:none
OPT_CLASS("-implicit:class"); // implicit compilation with -implicit:class
ImplicitType(String opt) {
this.opt = opt;
}
final String opt;
};
enum AnnoType {
NONE, // no annotation processing
SPECIFY // explicit annotation processing
};
public static void main(String ... args) throws Exception {
boolean ok = true;
// iterate over all combinations
for (ImplicitType implicitType: EnumSet.allOf(ImplicitType.class)) {
for (AnnoType annoType: EnumSet.allOf(AnnoType.class)) {
ok &= test(implicitType, annoType);
}
}
if (!ok)
throw new AssertionError("test failed");
}
/**
* Verify that a class file is generated, or not, for an implicitly compiled source file,
* and that the correct warning message is given for implicitly compiled files when annotation processing.
*/
static boolean test(ImplicitType implicitType, AnnoType annoType) throws IOException {
System.err.println("test implicit=" + implicitType + " anno=" + annoType);
// ensure clean start
a_class.delete();
b_class.delete();
processorServices.delete();
List<String> opts = new ArrayList<String>();
opts.addAll(Arrays.asList("-d", ".",
"-sourcepath", testSrc,
"-classpath", testClasses,
"-proc:full"));
if (implicitType.opt != null)
opts.add(implicitType.opt);
switch (annoType) {
case SPECIFY:
opts.addAll(Arrays.asList("-processor", Anno.class.getName()));
break;
}
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
MyDiagListener dl = new MyDiagListener();
try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
// Note: class A references class B, so compile A if we want implicit compilation
File file = (implicitType != ImplicitType.NONE) ? a_java : b_java;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
//System.err.println("compile: " + opts + " " + files);
boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
if (!ok) {
error("compilation failed");
return false;
}
// check implicit compilation results if necessary
if (implicitType != ImplicitType.NONE) {
boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
if (b_class.exists() != expectClass) {
if (b_class.exists())
error("B implicitly compiled unexpectedly");
else
error("B not impliictly compiled");
return false;
}
}
// check message key results
String expectKey = null;
if (implicitType == ImplicitType.OPT_UNSET) {
switch (annoType) {
case SPECIFY:
expectKey = "compiler.warn.proc.use.implicit";
break;
}
}
if (expectKey == null) {
if (dl.diagCodes.size() != 0) {
error("no diagnostics expected");
return false;
}
} else {
if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
error("unexpected diagnostics generated");
return false;
}
}
return true;
}
}
static void createProcessorServices(String name) throws IOException {
processorServices.getParentFile().mkdirs();
BufferedWriter out = new BufferedWriter(new FileWriter(processorServices));
out.write(name);
out.newLine();
out.close();
}
static class MyDiagListener implements DiagnosticListener<JavaFileObject> {
public void report(Diagnostic d) {
diagCodes.add(d.getCode());
System.err.println(d);
}
List<String> diagCodes = new ArrayList<String>();
}
static void error(String msg) {
System.err.println("ERROR: " + msg);
}
static File services(Class<?> service) {
String[] dirs = { testClasses, "META-INF", "services" };
File dir = null;
for (String d: dirs)
dir = (dir == null ? new File(d) : new File(dir, d));
return new File(dir, service.getName());
}
}

View file

@ -0,0 +1,41 @@
/*
* 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.
*/
/**
* @test
* @bug 6342411
* @summary Add bridge method to allow reflective access to public method in non-public class
* @author Neal M Gafter
*/
import a.Pub;
import java.lang.reflect.*;
public class T6342411 {
public static void main(String[] args) throws Exception {
Pub p = new Pub();
p.f();
Method m = Pub.class.getMethod("f");
m.invoke(p);
}
}

View file

@ -0,0 +1,30 @@
/*
* 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 a;
class Base {
public void f() {
System.out.println("Hello, world!");
}
}

View file

@ -0,0 +1,26 @@
/*
* 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 a;
public class Pub extends Base {}

View file

@ -0,0 +1,25 @@
/*
* @test /nodynamiccopyright/
* @bug 6360970
* @summary javac erroneously accept ambiguous field reference
* @compile/fail/ref=T6360970.out -XDrawDiagnostics T6360970.java
*/
class T6360970 {
interface A {
int i = 1;
}
interface B {
int i = 2;
}
interface C extends A, B { }
static class D {
public static final int i = 0;
}
static class E extends D implements C { }
int i = E.i; //ambiguous
}

View file

@ -0,0 +1,2 @@
T6360970.java:24:14: compiler.err.ref.ambiguous: i, kindname.variable, i, T6360970.D, kindname.variable, i, T6360970.A
1 error

View file

@ -0,0 +1,38 @@
/*
* 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 6390045
* @summary Unexpected error "cannot access java.lang.Void" with '-target cldc1.0' with -source >=1.5
*
* @author mcimadamore
* @compile -XDfailcomplete=java.lang.Void T6390045a.java
*/
class T6390045a {
boolean b;
short s;
Object o;
Object p = b ? o : s;
}

View file

@ -0,0 +1,38 @@
/*
* 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 6390045
* @summary Unexpected error "cannot access java.lang.Void" with '-target cldc1.0' with -source >=1.5
*
* @author mcimadamore
* @compile -XDfailcomplete=java.lang.Void T6390045b.java
*/
class T6390045b {
short s;
Object o;
Object p = choose(o, s);
<T> T choose(T t1, T t2) { return t1; }
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class A {
B b;
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class B { }

View file

@ -0,0 +1,146 @@
/*
* Copyright (c) 2006, 2015, 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 6394683
* @summary need to resolve different file-type precedence semantics for javac and 269
* @modules java.compiler
* jdk.compiler
*/
import java.io.*;
import javax.tools.*;
public class T6394683 {
static final String testSrc = System.getProperty("test.src", ".");
static final File a_java = new File(testSrc, "A.java");
static final File a_class = new File("A.class");
static final File b_class = new File("B.class");
static final File b_java = new File("B.java");
static abstract class TestFile extends File {
TestFile(File file) {
super(file.getPath());
}
abstract void create() throws IOException;
}
static class JavaTestFile extends TestFile {
JavaTestFile(File file, String text) {
super(file);
this.text = text;
}
void create() throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter(this));
out.write(text);
out.newLine();
out.close();
}
private String text;
}
static TestFile good_java = new JavaTestFile(b_java, "class B { }");
static TestFile bad_java = new JavaTestFile(b_java, "class B");
static TestFile good_class = new TestFile(b_class) {
void create() throws IOException {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
int rc = javac.run(null, null, null,
"-d", ".",
new File(testSrc, "B.java").getPath());
if (rc != 0)
throw new AssertionError("compilation failed, rc=" + rc + " creating B.class");
}
};
static TestFile bad_class = new TestFile(b_class) {
void create() throws IOException {
FileOutputStream out = new FileOutputStream(b_class);
out.close();
}
};
public static void main(String ... args) throws Exception {
boolean ok;
ok = test("-Xprefer:source", good_java, bad_class);
ok &= test("-Xprefer:source", bad_class, good_java);
ok &= test("-Xprefer:newer", bad_java, good_class);
ok &= test("-Xprefer:newer", bad_class, good_java);
if (!ok)
throw new AssertionError("test failed");
}
static boolean test(String opt, TestFile older, TestFile newer) throws Exception {
// ensure clean start
a_class.delete();
b_java.delete();
b_class.delete();
older.create();
newer.create();
if (!older.exists() || !newer.exists())
throw new AssertionError("error creating files");
int n = 0;
while (newer.lastModified() <= older.lastModified()) {
if (++n == 5)
throw new Error("Cannot create files");
Thread.sleep(1000);
newer.create();
}
System.err.println("test:"
+ "option:" + opt + ", "
+ "older:" + older + "[" + older.length() + ":" + older.lastModified() + "], "
+ "newer:" + newer + "[" + newer.length() + ":" + newer.lastModified() + "]");
for (String s: new File(".").list())
System.err.print(" " + s);
System.err.println();
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
int rc = javac.run(null, null, null,
"-d", ".",
"-classpath", ".",
"-sourcepath", ".",
opt,
a_java.getPath());
if (rc != 0) {
error("compilation failed, rc=" + rc + ", option: " + opt + ", older:" + older + ", newer" + newer);
return false;
}
return true;
}
static void error(String msg) {
System.err.println(msg);
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2006, 2015, 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 6400383
* @summary directory foo.java on javac command line causes javac to crash
* @modules jdk.compiler/com.sun.tools.javac.api
*/
import java.io.*;
import com.sun.tools.javac.api.*;
public class T6400383 {
public static void main(String... args) {
File foo = new File("foo.java");
foo.delete();
// case 1: file not found
JavacTool tool = JavacTool.create();
StringStream out = new StringStream();
tool.run(null, out, out, foo.getPath());
check(out.toString());
// case 2: file is a directory
out.clear();
try {
foo.mkdir();
tool.run(null, out, out, foo.getPath());
check(out.toString());
} finally {
foo.delete();
}
}
private static void check(String s) {
System.err.println(s);
// If the compiler crashed and caught the error, it will print out
// the "oh golly, I crashed!" message, which will contain the Java
// name of the exception in the stack trace ... so look for the
// string "Exception" or "Error".
if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1)
throw new AssertionError("found exception");
}
private static class StringStream extends OutputStream {
public void write(int i) {
sb.append((char) i);
}
void clear() {
sb.setLength(0);
}
public String toString() {
return sb.toString();
}
private StringBuilder sb = new StringBuilder();
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class A {
B b = new B();
B getB() { return b; }
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class B {
A a = new A();
A getA() { return a; }
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class C {
A a = new A();
B b = new B();
}

View file

@ -0,0 +1,151 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6400872
* @summary REGRESSION: Java Compiler cannot find jar files referenced by other
* @modules java.compiler
* jdk.compiler
* @run main T6400872
*/
// ${TESTJAVA}/bin/javac -d ${TESTCLASSES} ${TESTSRC}/A.java ${TESTSRC}/B.java
// ${TESTJAVA}/bin/jar -cfm A.jar ${TESTSRC}/A/META-INF/MANIFEST.MF -C ${TESTCLASSES} A.class
// ${TESTJAVA}/bin/jar -cfm B.jar ${TESTSRC}/B/META-INF/MANIFEST.MF -C ${TESTCLASSES} B.class
// ${TESTJAVA}/bin/javac -cp A.jar ${TESTSRC}/C.java
import java.io.*;
import java.nio.*;
import java.util.*;
import java.util.jar.*;
import javax.tools.*;
import javax.tools.StandardJavaFileManager.*;
public class T6400872 {
static File testSrc = new File(System.getProperty("test.src", "."));
static File testClasses = new File(System.getProperty("test.classes", "."));
public static void main(String... args) throws Exception {
// compile A.java and B.java
compile(testClasses, null, new File(testSrc, "A.java"), new File(testSrc, "B.java"));
// put them in mutually referential class files
jar(new File("A.jar"), iterable(new File(".", "B.jar")), testClasses, new File("A.class"));
jar(new File("B.jar"), iterable(new File(".", "A.jar")), testClasses, new File("B.class"));
// verify we can successfully use the class path entries in the jar files
compile(new File("."), iterable(new File("A.jar")), new File(testSrc, "C.java"));
}
static void compile(File classOutDir, Iterable<File> classPath, File... files)
throws IOException {
System.err.println("compile...");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fileObjects =
fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
List<String> options = new ArrayList<String>();
if (classOutDir != null) {
options.add("-d");
options.add(classOutDir.getPath());
}
if (classPath != null) {
options.add("-classpath");
options.add(join(classPath, File.pathSeparator));
}
options.add("-verbose");
JavaCompiler.CompilationTask task =
compiler.getTask(null, fm, null, options, null, fileObjects);
if (!task.call())
throw new AssertionError("compilation failed");
}
}
static void jar(File jar, Iterable<File> classPath, File base, File... files)
throws IOException {
System.err.println("jar...");
Manifest m = new Manifest();
if (classPath != null) {
Attributes mainAttrs = m.getMainAttributes();
mainAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
mainAttrs.put(Attributes.Name.CLASS_PATH, join(classPath, " "));
}
try (JarOutputStream j = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jar)), m)) {
add(j, base, files);
}
}
static void add(JarOutputStream j, File base, File... files) throws IOException {
if (files == null)
return;
for (File f: files)
add(j, base, f);
}
static void add(JarOutputStream j, File base, File file) throws IOException {
File f = new File(base, file.getPath());
if (f.isDirectory()) {
String[] children = f.list();
if (children != null)
for (String c: children)
add(j, base, new File(file, c));
} else {
JarEntry e = new JarEntry(file.getPath());
e.setSize(f.length());
j.putNextEntry(e);
j.write(read(f));
j.closeEntry();
}
}
static byte[] read(File f) throws IOException {
byte[] buf = new byte[(int) f.length()];
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(f))) {
int offset = 0;
while (offset < buf.length) {
int n = in.read(buf, offset, buf.length - offset);
if (n < 0)
throw new EOFException();
offset += n;
}
return buf;
}
}
static <T> Iterable<T> iterable(T single) {
return Collections.singleton(single);
}
static <T> String join(Iterable<T> iter, String sep) {
StringBuilder p = new StringBuilder();
for (T t: iter) {
if (p.length() > 0)
p.append(' ');
p.append(t);
}
return p.toString();
}
}

View file

@ -0,0 +1,29 @@
/*
* 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.
*/
package p;
public class A {
public int publ;
protected int prot;
private int priv;
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2006, 2015, 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 6402516
* @summary need Trees.getScope(TreePath)
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
* @build Checker CheckClass
* @run main CheckClass
*/
import java.util.*;
import com.sun.source.tree.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
/*
* Check the enclosing class of a scope against the contents of string literals.
*/
public class CheckClass extends Checker {
public static void main(String... args) throws Exception {
Checker chk = new CheckClass();
chk.check("TestClass.java");
}
@Override
protected boolean checkLocal(Scope s, String ref) {
//System.err.println("checkLocal: " + s + " " + ref + " " + s.getEnclosingClass());
TypeElement te = s.getEnclosingClass();
boolean ok;
if (te == null)
ok = ref.equals("0");
else {
CharSequence name = te.getQualifiedName();
ok = ref.equals(name == null || name.length() == 0 ? "-" : name.toString());
}
if (!ok)
error(s, ref, "bad enclosing class found: " + te);
return ok;
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2006, 2015, 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 6402516
* @summary need Trees.getScope(TreePath)
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
* @build Checker CheckIsAccessible
* @run main CheckIsAccessible
*/
import java.util.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
/*
* Check the accessibility of items of a scope against the contents of string literals.
*/
public class CheckIsAccessible extends Checker {
public static void main(String... args) throws Exception {
Checker chk = new CheckIsAccessible();
chk.check("TestIsAccessible.java", "A.java");
}
@Override
protected boolean check(Scope s, String ref) {
System.err.println("checkIsAccessible: " + s + " " + s.getEnclosingClass() + " " + ref);
if (ref.length() == 0)
return true;
Trees trees = getTrees();
String[] args = ref.split(" +", 3);
boolean expect = args[args.length - 1].equals("yes");
boolean actual;
switch (args.length) {
case 2:
TypeElement te = getTypeElement(args[0]);
actual = trees.isAccessible(s, te);
if (actual != expect)
error(s, ref, "accessible issue found: " + te + " " + actual);
break;
case 3:
DeclaredType site = getType(args[0]);
Element member = getMember(args[1]);
actual = trees.isAccessible(s, member, site);
if (actual != expect)
error(s, ref, "accessible issue found: " + member + "@" + site + " " + actual);
break;
default:
throw new IllegalArgumentException(ref);
}
return (actual == expect);
}
private TypeElement getTypeElement(String name) {
TypeElement te = getElements().getTypeElement(name);
if (te == null)
throw new IllegalArgumentException("can't find element " + name);
return te;
}
private DeclaredType getType(String name) {
return (DeclaredType)(getTypeElement(name).asType());
}
private Element getMember(String name) {
int sep = name.indexOf("#");
String tname = name.substring(0, sep);
String mname = name.substring(sep+1);
TypeElement te = getTypeElement(tname);
for (Element e: te.getEnclosedElements()) {
if (mname.contentEquals(e.getSimpleName()))
return e;
}
throw new IllegalArgumentException("can't find member " + mname + " in " + tname);
}
}

View file

@ -0,0 +1,131 @@
/*
* Copyright (c) 2006, 2019, 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 6402516 8031569
* @summary need Trees.getScope(TreePath)
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
* @build Checker CheckLocalElements
* @run main CheckLocalElements
*/
import java.io.IOException;
import java.util.*;
import java.util.regex.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
/*
* Check the local elements of a scope against the contents of string literals and top-level comment.
*/
public class CheckLocalElements extends Checker {
public static void main(String... args) throws Exception {
Checker chk = new CheckLocalElements();
chk.check("TestLocalElements.java");
}
@Override
protected boolean checkLocal(Scope s, String ref) {
Iterator<? extends Element> elemIter = s.getLocalElements().iterator();
ref = ref.trim();
String[] refs = ref.length() == 0 ? new String[0] : ref.split("[ ]*,[ ]*", -1);
Iterator<String> refIter = Arrays.asList(refs).iterator();
String r = null;
nextElem:
while (elemIter.hasNext()) {
Element e = elemIter.next();
try {
if (r == null)
r = refIter.next();
while (r.endsWith(".*")) {
String encl = getEnclosingName(e);
String rBase = r.substring(0, r.length() - 2);
if (encl.equals(rBase) || encl.startsWith(rBase + "."))
continue nextElem;
r = refIter.next();
}
if (r.equals("-") && (e.getSimpleName().length() == 0)
|| e.getSimpleName().toString().equals(r)) {
r = null;
continue nextElem;
}
error(s, ref, "mismatch: " + e.getSimpleName() + " " + r);
return false;
} catch (NoSuchElementException ex) { // from refIter.next()
error(s, null, "scope has unexpected entry: " + e.getSimpleName());
return false;
}
}
if (refIter.hasNext()) {
error(s, ref, "scope is missing entry: " + refIter.next());
return false;
}
return true;
}
@Override
void additionalChecks(Trees trees, CompilationUnitTree topLevel) throws IOException {
Matcher m = TOPLEVEL_SCOPE_DEF.matcher(topLevel.getSourceFile().getCharContent(false));
if (!m.find())
throw new AssertionError("Should have top-level scope def!");
check(trees.getScope(new TreePath(topLevel)), m.group(1));
}
//where:
Pattern TOPLEVEL_SCOPE_DEF = Pattern.compile("TOPLEVEL_SCOPE:(.*)");
private String getEnclosingName(Element e) {
Element encl = e.getEnclosingElement();
return encl == null ? "" : encl.accept(qualNameVisitor, null);
}
private ElementVisitor<String,Void> qualNameVisitor = new SimpleElementVisitor14<String,Void>() {
protected String defaultAction(Element e, Void ignore) {
return "";
}
public String visitPackage(PackageElement e, Void ignore) {
return e.getQualifiedName().toString();
}
public String visitType(TypeElement e, Void ignore) {
return e.getQualifiedName().toString();
}
};
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2006, 2015, 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 6402516
* @summary need Trees.getScope(TreePath)
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
* @build Checker CheckMethod
* @run main CheckMethod
*/
import java.util.*;
import com.sun.source.tree.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
/*
* Check the enclosing method of a scope against the contents of string literals.
*/
public class CheckMethod extends Checker {
public static void main(String... args) throws Exception {
Checker chk = new CheckMethod();
chk.check("TestMethod.java");
}
@Override
protected boolean checkLocal(Scope s, String ref) {
//System.err.println("checkLocal: " + s + " " + ref + " " + s.getEnclosingMethod());
ExecutableElement ee = s.getEnclosingMethod();
boolean ok;
if (ee == null)
ok = ref.equals("0");
else {
CharSequence name = ee.getSimpleName();
ok = ref.equals(name == null || name.length() == 0 ? "-" : name.toString());
}
if (!ok)
error(s, ref, "bad enclosing method found: " + ee);
return ok;
}
}

View file

@ -0,0 +1,174 @@
/*
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.*;
import java.util.*;
import javax.lang.model.util.*;
import javax.tools.*;
import com.sun.tools.javac.api.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.Position;
/*
* Abstract class to help check the scopes in a parsed source file.
* -- parse source file
* -- scan trees looking for string literals
* -- check the scope at that point against the string, using
* boolean check(Scope s, String ref)
*/
abstract class Checker {
// parse the source file and call check(scope, string) for each string literal found
void check(String... fileNames) throws IOException {
File testSrc = new File(System.getProperty("test.src"));
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic d) {
System.err.println(d);
if (d.getKind() == Diagnostic.Kind.ERROR)
errors = true;
new Exception().printStackTrace();
}
};
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames));
task = tool.getTask(null, fm, dl, null, null, files);
Iterable<? extends CompilationUnitTree> units = task.parse();
if (errors)
throw new AssertionError("errors occurred creating trees");
ScopeScanner s = new ScopeScanner();
for (CompilationUnitTree unit: units) {
TreePath p = new TreePath(unit);
s.scan(p, getTrees());
additionalChecks(getTrees(), unit);
}
task = null;
if (errors)
throw new AssertionError("errors occurred checking scopes");
}
}
// default impl: split ref at ";" and call checkLocal(scope, ref_segment) on scope and its enclosing scopes
protected boolean check(Scope s, String ref) {
// System.err.println("check scope: " + s);
// System.err.println("check ref: " + ref);
if (s == null && (ref == null || ref.trim().length() == 0))
return true;
if (s == null) {
error(s, ref, "scope missing");
return false;
}
if (ref == null) {
error(s, ref, "scope unexpected");
return false;
}
String local;
String encl;
int semi = ref.indexOf(';');
if (semi == -1) {
local = ref;
encl = null;
} else {
local = ref.substring(0, semi);
encl = ref.substring(semi + 1);
}
return checkLocal(s, local.trim())
& check(s.getEnclosingScope(), encl);
}
// override if using default check(Scope,String)
boolean checkLocal(Scope s, String ref) {
throw new IllegalStateException();
}
void additionalChecks(Trees trees, CompilationUnitTree topLevel) throws IOException {
}
void error(Scope s, String ref, String msg) {
System.err.println("Error: " + msg);
System.err.println("Scope: " + (s == null ? null : asList(s.getLocalElements())));
System.err.println("Expect: " + ref);
System.err.println("javac: " + (s == null ? null : ((JavacScope) s).getEnv()));
errors = true;
}
protected Elements getElements() {
return task.getElements();
}
protected Trees getTrees() {
return Trees.instance(task);
}
boolean errors = false;
protected JavacTask task;
// scan a parse tree, and for every string literal found, call check(scope, string) with
// the string value at the scope at that point
class ScopeScanner extends TreePathScanner<Boolean,Trees> {
public Boolean visitLiteral(LiteralTree tree, Trees trees) {
TreePath path = getCurrentPath();
CompilationUnitTree unit = path.getCompilationUnit();
Position.LineMap lineMap = ((JCCompilationUnit)unit).lineMap;
// long line = lineMap.getLineNumber(((JCTree)tree).pos/*trees.getSourcePositions().getStartPosition(tree)*/);
// System.err.println(line + ": " + abbrev(tree));
Scope s = trees.getScope(path);
if (tree.getKind() == Tree.Kind.STRING_LITERAL)
check(s, tree.getValue().toString().trim());
return null;
}
private String abbrev(Tree tree) {
int max = 48;
String s = tree.toString().replaceAll("[ \n]+", " ");
return (s.length() < max ? s : s.substring(0, max-3) + "...");
}
}
// prefix filenames with a directory
static Iterable<File> getFiles(File dir, String... names) {
List<File> files = new ArrayList<File>(names.length);
for (String name: names)
files.add(new File(dir, name));
return files;
}
static private <T> List<T> asList(Iterable<T> iter) {
List<T> l = new ArrayList<T>();
for (T t: iter)
l.add(t);
return l;
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2006, 2024, 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.
*/
// 0 means no enclosing class
// - means anonymous enclosing class
class Test {
void m1(int m1_arg) {
String x = "Test; 0; 0; 0";
String y = "Test; 0; 0; 0";
String z = "Test; 0; 0; 0";
Object o = new Object() {
public boolean equals(Object other) {
String p = "-; Test; 0; 0; 0";
String q = "-; Test; 0; 0; 0";
String r = "-; Test; 0; 0; 0";
return (this == other);
}
};
}
String s = "Test; 0; 0; 0";
boolean b = new Object() {
public boolean equals(Object other) {
String p = "-; Test; 0; 0; 0";
String q = "-; Test; 0; 0; 0";
String r = "-; Test; 0; 0; 0";
return (this == other);
}
}.equals(null);
class Test2 {
String s = "Test.Test2; Test; 0; 0; 0";
}
}

View file

@ -0,0 +1,54 @@
/*
* 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.
*/
import p.A;
class Test1 {
String ss = " p.A yes";
String sa = "p.A p.A#publ yes";
String sq = "p.A p.A#prot no ";
String sr = "Test2 p.A#prot no ";
String sx = "p.A p.A#priv no ";
String s2 = " Test2 yes";
String s3 = "Test2 Test2#stat yes";
static class Test1a {
String s1 = "Test2 Test2#priv no";
}
}
class Test2 extends A {
private int priv;
static int stat;
String ss = " p.A yes";
String sa = "p.A p.A#publ yes";
String sq = "p.A p.A#prot no ";
String sr = "Test2 p.A#prot yes";
String sx = "p.A p.A#priv no ";
static class Test2a {
String s1 = "Test2 Test2#priv yes";
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2006, 2024, 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.List;
import java.io.*;
//TOPLEVEL_SCOPE:List, Test2, Test; java.io.*, java.lang.*;
class Test {
void m1(int m1_arg) {
String x = "x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String y = "y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String z = "z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
Object o = new Object() {
public boolean equals(Object other) {
String p = "p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String q = "q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String r = "r, q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;";
return (this == other);
}
};
}
String s = "super, this; List, Test2, Test; java.io.*, java.lang.*;";
boolean b = new Object() {
public boolean equals(Object other) {
String p = "p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String q = "q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;";
String r = "r, q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;";
return (this == other);
}
}.equals(null);
}
class Test2 { }

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2006, 2024, 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.
*/
// 0 means no enclosing method
class Test {
void m1(int m1_arg) {
String x = "m1; 0; 0; 0";
String y = "m1; 0; 0; 0";
String z = "m1; 0; 0; 0";
Object o = new Object() {
public boolean equals(Object other) {
String p = "equals; m1; 0; 0; 0";
String q = "equals; m1; 0; 0; 0";
String r = "equals; m1; 0; 0; 0";
return (this == other);
}
};
}
String s = "0; 0; 0; 0";
boolean b = new Object() {
public boolean equals(Object other) {
String p = "equals; 0; 0; 0; 0";
String q = "equals; 0; 0; 0; 0";
String r = "equals; 0; 0; 0; 0";
return (this == other);
}
}.equals(null);
class Test2 {
String s = "0; 0; 0; 0; 0";
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class A { }

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class B extends A { }

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2006, 2015, 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 6403424
* @summary JavacFileManager.inferBinaryName is not case-insensitive on Windows
* @modules jdk.compiler/com.sun.tools.javac.api
*/
import java.io.*;
import java.util.*;
import com.sun.tools.javac.api.*;
public class T6403424 {
public static void main(String[] args) {
File testSrc = new File(System.getProperty("test.src", "."));
File TMP = new File("TMP");
TMP.mkdirs();
// first, compile A to the TMP directory
File A_java = new File(testSrc, "A.java");
compile("-d", TMP.getPath(), A_java.getPath());
// now compile B, which references A,
// with TMP on classpath and tmp on bootclasspath
File B_java = new File(testSrc, "B.java");
compile("-source", "8", "-target", "8", // can't use -Xbootclasspath/p after 8
"-classpath", TMP.getPath(),
"-Xbootclasspath/p:" + TMP.getPath().toLowerCase(),
"-d", ".",
B_java.getPath());
// should not get NPE from compiler
}
private static void compile(String... args) {
System.err.println("compile: " + Arrays.asList(args));
JavacTool javac = JavacTool.create();
int rc = javac.run(null, null, null, args);
if (rc != 0)
throw new AssertionError("test compilation failed");
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class A {
public static void m() {
1+1
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2006, 2015, 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 6440583
* @summary better error recovery
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.tree
* jdk.compiler/com.sun.tools.javac.util
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
import com.sun.tools.javac.tree.JCTree.*;
public class T6440583 {
public static void main(String... args) throws Exception {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends Tree> trees = task.parse();
TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {
public Boolean visitErroneous(ErroneousTree tree, Void ignore) {
JCErroneous etree = (JCErroneous) tree;
List<? extends Tree> errs = etree.getErrorTrees();
System.err.println("errs: " + errs);
if (errs == null || errs.size() == 0)
throw new AssertionError("no error trees found");
found = true;
return true;
}
};
for (Tree tree: trees)
checker.scan(tree, null);
if (!found)
throw new AssertionError("no ErroneousTree nodes found");
}
}
private static boolean found;
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2006, 2025, 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é
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.util
*/
import java.io.IOException;
import java.net.URI;
import javax.lang.model.element.Element;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.JavacTool;
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 {
Context context = new Context();
MyMessages.preRegister(context);
JavacTool tool = JavacTool.create();
JavacTask task = tool.getTask(null, null, null, null, null,
List.of(new MyFileObject()),
context);
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);
}
}
}

View file

@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @bug 6491592
* @summary Compiler crashes on assignment operator
* @author alex.buckley@...
* @compile/fail/ref=T6491592.out -XDrawDiagnostics T6491592.java
*/
public class T6491592 {
public static void meth() {
Object o = null;
o += null;
}
}

View file

@ -0,0 +1,2 @@
T6491592.java:12:11: compiler.err.operator.cant.be.applied.1: +, java.lang.Object, compiler.misc.type.null
1 error

View file

@ -0,0 +1,151 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6508981
* @summary cleanup file separator handling in JavacFileManager
* (This test is specifically to test the new impl of inferBinaryName)
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build toolbox.ToolBox toolbox.JarTask p.A
* @run main TestInferBinaryName
*/
import java.io.*;
import java.util.*;
import javax.tools.*;
import static javax.tools.JavaFileObject.Kind.*;
import static javax.tools.StandardLocation.*;
import toolbox.JarTask;
import toolbox.ToolBox;
/**
* Verify the various implementations of inferBinaryName, but configuring
* different instances of a file manager, getting a file object, and checking
* the impl of inferBinaryName for that file object.
*/
public class TestInferBinaryName {
public static void main(String... args) throws Exception {
new TestInferBinaryName().run();
}
void run() throws Exception {
testDirectory();
File testJar = createJar();
testZipArchive(testJar);
if (errors > 0)
throw new Exception(errors + " error found");
}
File createJar() throws IOException {
File f = new File("test.jar");
try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler()
.getStandardFileManager(null, null, null)) {
ToolBox tb = new ToolBox();
new JarTask(tb, f.getPath())
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
.run();
}
return f;
}
void testDirectory() throws IOException {
String testClassName = "p.A";
List<File> testClasses = Arrays.asList(new File(System.getProperty("test.classes")));
try (JavaFileManager fm = getFileManager(testClasses)) {
test("testDirectory",
fm, testClassName, "SimpleFileObject");
}
}
void testZipArchive(File testJar) throws IOException {
String testClassName = "java.lang.String";
List<File> path = Arrays.asList(testJar);
try (JavaFileManager fm = getFileManager(path)) {
test("testZipArchive",
fm, testClassName, "JarFileObject");
}
}
/**
* @param testName for debugging
* @param fm suitably configured file manager
* @param testClassName the classname to test
* @param implClassName the expected classname of the JavaFileObject impl,
* used for checking that we are checking the expected impl of
* inferBinaryName
*/
void test(String testName,
JavaFileManager fm, String testClassName, String implClassName) throws IOException {
JavaFileObject fo = fm.getJavaFileForInput(CLASS_PATH, testClassName, CLASS);
if (fo == null) {
System.err.println("Can't find " + testClassName);
errors++;
return;
}
String cn = fo.getClass().getSimpleName();
String bn = fm.inferBinaryName(CLASS_PATH, fo);
System.err.println(testName + " " + cn + " " + bn);
checkEqual(cn, implClassName);
checkEqual(bn, testClassName);
System.err.println("OK");
}
JavaFileManager getFileManager(List<File> path)
throws IOException {
StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler()
.getStandardFileManager(null, null, null);
fm.setLocation(CLASS_PATH, path);
return fm;
}
List<File> getPath(String s) {
List<File> path = new ArrayList<>();
for (String f: s.split(File.pathSeparator)) {
if (f.length() > 0)
path.add(new File(f));
}
//System.err.println("path: " + path);
return path;
}
void checkEqual(String found, String expect) {
if (!found.equals(expect)) {
System.err.println("Expected: " + expect);
System.err.println(" Found: " + found);
errors++;
}
}
private int errors;
}
class A { }

View file

@ -0,0 +1,25 @@
/*
* 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.
*/
package p;
class A { }

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.Serializable;
public class T {
public static void main(String[] args) {
T t = new T();
t.createObject();
}
public Object createObject() {
return new Serializable() {
void method() {
}
};
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6520152
* @summary ACC_FINAL flag for anonymous classes shouldn't be set
* @compile T.java
* @run main/othervm T6520152
*/
import java.lang.reflect.Method;
import static java.lang.reflect.Modifier.*;
public class T6520152 {
public static void main(String [] args) throws Exception {
Class clazz = Class.forName("T$1");
if ((clazz.getModifiers() & FINAL) != 0) {
throw new RuntimeException("Failed: " + clazz.getName() + " shouldn't be marked final.");
}
}
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6521805
* @summary Regression: JDK5/JDK6 javac allows write access to outer class reference
* @author mcimadamore
*
* @compile T6521805b.java
*/
class T6521805b {
static class Outer {
String this$0 = null;
}
public class Inner extends Outer {
public void foo() {
this$0 = "Hello!";
}
}
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6521805
* @summary Regression: JDK5/JDK6 javac allows write access to outer class reference
* @author mcimadamore
*
* @compile T6521805c.java
*/
class T6521805c {
static class Outer {
T6521805c this$0() { return null;}
}
public class Inner extends Outer {
public void foo() {
this$0();
}
}
}

View file

@ -0,0 +1,34 @@
/*
* @test /nodynamiccopyright/
* @bug 6521805
* @summary Regression: JDK5/JDK6 javac allows write access to outer class reference
* @author mcimadamore
*
* @compile/fail/ref=T6521805d.out T6521805d.java -XDrawDiagnostics
*/
import java.util.Objects;
class T6521805 {
static class Inner extends T6521805.Outer {
Inner(T6521805 t) {
t.super();
}
T6521805 this$0 = null;
public void foo() {
this$0 = new T6521805();
}
}
class Outer {
{
// access enclosing instance so this$0 field is generated
Objects.requireNonNull(T6521805.this);
}
}
}

View file

@ -0,0 +1,2 @@
T6521805d.java:20:18: compiler.err.cannot.generate.class: T6521805.Inner, (compiler.misc.synthetic.name.conflict: this$0, T6521805.Inner)
1 error

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6521805
* @summary Regression: JDK5/JDK6 javac allows write access to outer class reference
* @author mcimadamore
*
* @compile/fail/ref=T6521805e.out p/Outer.java p/Sub.java -XDrawDiagnostics
* @compile/fail/ref=T6521805e.out p/Sub.java p/Outer.java -XDrawDiagnostics
*/

View file

@ -0,0 +1,2 @@
Sub.java:10:11: compiler.err.cannot.generate.class: p.Inner, (compiler.misc.synthetic.name.conflict: this$0, p.Inner)
1 error

View file

@ -0,0 +1,14 @@
/* /nodynamiccopyright/ */
package p;
import java.util.Objects;
class Outer {
class Super {
{
// access enclosing instance so this$0 field is generated
Objects.requireNonNull(Outer.this);
}
}
}

View file

@ -0,0 +1,15 @@
/* /nodynamiccopyright/ */
package p;
class Inner extends Outer.Super {
Inner(Outer t) {
t.super();
}
Outer this$0 = null;
public void foo() {
this$0 = new Outer();
}
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6547131
* @summary java.lang.ClassFormatError when using old collection API
* @compile p/Outer.jasm p/Outer$I.jasm T.java
* @run main T
*/
import p.*;
class SubI implements Outer.I {
SubI() { }
Outer.I getI() { return this; }
}
public class T {
public static void main(String argv[]){
SubI sub = new SubI();
Outer.I inter = (Outer.I)sub.getI();
}
}

View file

@ -0,0 +1,10 @@
package p;
public interface Outer$I
version 49:0
{
public static interface InnerClass I=class Outer$I of class Outer;
} // end Class Outer$I

View file

@ -0,0 +1,18 @@
package p;
super public class Outer
version 49:0
{
public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
public static interface InnerClass I=class Outer$I of class Outer;
} // end Class Outer

View file

@ -0,0 +1,308 @@
/*
* @test /nodynamiccopyright/
* @bug 6558548 7039937
* @summary The compiler needs to be aligned with clarified specification of throws
* @compile/fail/ref=T6558548_latest.out -XDrawDiagnostics T6558548.java
*/
class T6558548 {
void nothing() {}
void checked() throws InterruptedException {}
void runtime() throws IllegalArgumentException {}
void m1a() {
try {
throw new java.io.FileNotFoundException();
}
catch(java.io.FileNotFoundException exc) { }
catch(java.io.IOException exc) { } // 6: ok; latest: unreachable
}
void m1b() {
try {
throw new java.io.IOException();
}
catch(java.io.FileNotFoundException exc) { }
catch(java.io.IOException exc) { } //ok
}
void m1c() {
try {
throw new java.io.FileNotFoundException();
}
catch(java.io.FileNotFoundException exc) { }
catch(Exception ex) { } //ok (Exception/Throwable always allowed)
}
void m1d() {
try {
throw new java.io.FileNotFoundException();
}
catch(java.io.FileNotFoundException exc) { }
catch(Throwable ex) { } //ok (Exception/Throwable always allowed)
}
void m3() {
try {
checked();
}
catch(Exception exc) { } //ok
}
void m4() {
try {
runtime();
}
catch(Exception exc) { } //ok
}
void m5() {
try {
nothing();
}
catch(Throwable exc) { } //ok
}
void m6() {
try {
checked();
}
catch(Throwable exc) { } //ok
}
void m7() {
try {
runtime();
}
catch(Throwable exc) { } //ok
}
void m9() {
try {
checked();
}
catch(Error exc) { }
catch(Throwable exc) { } //ok
}
void m10() {
try {
runtime();
}
catch(Error exc) { }
catch(Throwable exc) { } //ok
}
void m11() {
try {
nothing();
}
catch(Error exc) { }
catch(Throwable exc) { } //ok
}
void m12() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Throwable exc) { } // ok
}
void m13() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Throwable exc) { } // ok
}
void m14() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Throwable exc) { } // ok
}
void m15() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } //ok
}
void m16() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m17() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m18() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(InterruptedException exc) { }
catch(Exception exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m19() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(InterruptedException exc) { } //never thrown in try
catch(Exception exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m20() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(InterruptedException exc) { } //never thrown in try
catch(Exception exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m21() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } // ok
}
void m22() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } // 6: ok; latest: ok (Exception/Throwable always allowed)
}
void m23() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Exception exc) { } // 6: ok; latest: ok (Exception/Throwable always allowed)
}
void m24() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //ok
}
void m25() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m26() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m27() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(InterruptedException exc) { }
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m28() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(InterruptedException exc) { } //never thrown in try
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m29() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(InterruptedException exc) { } //never thrown in try
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m30() {
try {
checked();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //ok
}
void m31() {
try {
runtime();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m32() {
try {
nothing();
}
catch(RuntimeException exc) { }
catch(Error exc) { }
catch(Throwable exc) { } //6: ok; latest: ok (Exception/Throwable always allowed)
}
void m33() {
try {
checked();
}
catch(InterruptedException exc) { } //ok
}
void m34() {
try {
runtime();
}
catch(InterruptedException exc) { } //never thrown in try
}
void m35() {
try {
nothing();
}
catch(InterruptedException exc) { } //never thrown in try
}
}

View file

@ -0,0 +1,9 @@
T6558548.java:19:9: compiler.warn.unreachable.catch: java.io.FileNotFoundException
T6558548.java:167:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
T6558548.java:176:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
T6558548.java:247:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
T6558548.java:257:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
T6558548.java:299:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
T6558548.java:306:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException
6 errors
1 warning

View file

@ -0,0 +1,71 @@
/*
* @test /nodynamiccopyright/
* @bug 6563143 8008436 8009138
* @summary javac should issue a warning for overriding equals without hashCode
* @summary javac should not issue a warning for overriding equals without hasCode
* @summary javac, equals-hashCode warning tuning
* if hashCode has been overriden by a superclass
* @compile/ref=EqualsHashCodeWarningTest.out -Xlint:overrides -XDrawDiagnostics EqualsHashCodeWarningTest.java
*/
import java.util.Comparator;
public class EqualsHashCodeWarningTest {
@Override
public boolean equals(Object o) {
return o == this;
}
@Override
public int hashCode() {
return 0;
}
public Comparator m() {
return new Comparator() {
@Override
public boolean equals(Object o) {return true;}
@Override
public int compare(Object o1, Object o2) {
return 0;
}
};
}
}
class SubClass extends EqualsHashCodeWarningTest {
@Override
public boolean equals(Object o) {
return true;
}
}
@SuppressWarnings("overrides")
class DontWarnMe {
@Override
public boolean equals(Object o) {
return true;
}
}
class DoWarnMe {
@Override
public boolean equals(Object o) {
return o == this;
}
}
abstract class IamAbstractGetMeOutOfHere {
public boolean equals(Object o){return true;}
}
interface I {
public boolean equals(Object o);
}
enum E {
A, B
}
@interface anno {}

View file

@ -0,0 +1,2 @@
EqualsHashCodeWarningTest.java:52:1: compiler.warn.override.equals.but.not.hashcode: DoWarnMe
1 warning

View file

@ -0,0 +1,12 @@
/*
* @test /nodynamiccopyright/
* @bug 8242802
* @summary Verify javac does not crash while checking for equals/hashCode overrides
* @compile/fail/ref=InvalidAnonymous.out -XDrawDiagnostics InvalidAnonymous.java
* @compile/fail/ref=InvalidAnonymous.out -XDrawDiagnostics -Xlint:overrides InvalidAnonymous.java
*/
public class InvalidAnonymous {
private void t() {
new Undefined() {};
}
}

View file

@ -0,0 +1,2 @@
InvalidAnonymous.java:10:13: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, InvalidAnonymous, null)
1 error

Some files were not shown because too many files have changed in this diff Show more