6627362: javac generates code that uses array.clone, which is not available on JavaCard

6627364: javac needs Float and Double on the bootclasspath even when not directly used
6627366: javac needs Cloneable and Serializable on the classpath even when not directly used

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2008-08-01 15:23:18 -07:00
parent c936a75ed0
commit 7c754d9268
23 changed files with 923 additions and 20 deletions

View File

@ -75,6 +75,7 @@ public class Symtab {
private final Name.Table names;
private final ClassReader reader;
private final Target target;
/** A symbol for the root package.
*/
@ -144,6 +145,7 @@ public class Symtab {
public final Type suppressWarningsType;
public final Type inheritedType;
public final Type proprietaryType;
public final Type systemType;
/** The symbol representing the length field of an array.
*/
@ -272,6 +274,55 @@ public class Symtab {
return reader.enterClass(names.fromString(s)).type;
}
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
final Completer completer = type.tsym.completer;
if (completer != null) {
type.tsym.completer = new Completer() {
public void complete(Symbol sym) throws CompletionFailure {
try {
completer.complete(sym);
} catch (CompletionFailure e) {
sym.flags_field |= (PUBLIC | INTERFACE);
((ClassType) sym.type).supertype_field = objectType;
}
}
};
}
}
public void synthesizeBoxTypeIfMissing(final Type type) {
ClassSymbol sym = reader.enterClass(boxedName[type.tag]);
final Completer completer = sym.completer;
if (completer != null) {
sym.completer = new Completer() {
public void complete(Symbol sym) throws CompletionFailure {
try {
completer.complete(sym);
} catch (CompletionFailure e) {
sym.flags_field |= PUBLIC;
((ClassType) sym.type).supertype_field = objectType;
Name n = target.boxWithConstructors() ? names.init : names.valueOf;
MethodSymbol boxMethod =
new MethodSymbol(PUBLIC | STATIC,
n,
new MethodType(List.of(type), sym.type,
List.<Type>nil(), methodClass),
sym);
sym.members().enter(boxMethod);
MethodSymbol unboxMethod =
new MethodSymbol(PUBLIC,
type.tsym.name.append(names.Value), // x.intValue()
new MethodType(List.<Type>nil(), type,
List.<Type>nil(), methodClass),
sym);
sym.members().enter(unboxMethod);
}
}
};
}
}
/** Constructor; enters all predefined identifiers and operators
* into symbol table.
*/
@ -279,6 +330,7 @@ public class Symtab {
context.put(symtabKey, this);
names = Name.Table.instance(context);
target = Target.instance(context);
// Create the unknown type
unknownType = new Type(TypeTags.UNKNOWN, null);
@ -373,7 +425,7 @@ public class Symtab {
collectionsType = enterClass("java.util.Collections");
comparableType = enterClass("java.lang.Comparable");
arraysType = enterClass("java.util.Arrays");
iterableType = Target.instance(context).hasIterable()
iterableType = target.hasIterable()
? enterClass("java.lang.Iterable")
: enterClass("java.util.Collection");
iteratorType = enterClass("java.util.Iterator");
@ -383,6 +435,12 @@ public class Symtab {
deprecatedType = enterClass("java.lang.Deprecated");
suppressWarningsType = enterClass("java.lang.SuppressWarnings");
inheritedType = enterClass("java.lang.annotation.Inherited");
systemType = enterClass("java.lang.System");
synthesizeEmptyInterfaceIfMissing(cloneableType);
synthesizeEmptyInterfaceIfMissing(serializableType);
synthesizeBoxTypeIfMissing(doubleType);
synthesizeBoxTypeIfMissing(floatType);
// Enter a synthetic class that is used to mark Sun
// proprietary classes in ct.sym. This class does not have a

View File

@ -2110,16 +2110,64 @@ public class Lower extends TreeTranslator {
Symbol valuesSym = lookupMethod(tree.pos(), names.values,
tree.type, List.<Type>nil());
JCTypeCast valuesResult =
make.TypeCast(valuesSym.type.getReturnType(),
make.App(make.Select(make.Ident(valuesVar),
syms.arrayCloneMethod)));
List<JCStatement> valuesBody;
if (useClone()) {
// return (T[]) $VALUES.clone();
JCTypeCast valuesResult =
make.TypeCast(valuesSym.type.getReturnType(),
make.App(make.Select(make.Ident(valuesVar),
syms.arrayCloneMethod)));
valuesBody = List.<JCStatement>of(make.Return(valuesResult));
} else {
// template: T[] $result = new T[$values.length];
Name resultName = names.fromString(target.syntheticNameChar() + "result");
while (tree.sym.members().lookup(resultName).scope != null) // avoid name clash
resultName = names.fromString(resultName + "" + target.syntheticNameChar());
VarSymbol resultVar = new VarSymbol(FINAL|SYNTHETIC,
resultName,
arrayType,
valuesSym);
JCNewArray resultArray = make.NewArray(make.Type(types.erasure(tree.type)),
List.of(make.Select(make.Ident(valuesVar), syms.lengthVar)),
null);
resultArray.type = arrayType;
JCVariableDecl decl = make.VarDef(resultVar, resultArray);
// template: System.arraycopy($VALUES, 0, $result, 0, $VALUES.length);
if (systemArraycopyMethod == null) {
systemArraycopyMethod =
new MethodSymbol(PUBLIC | STATIC,
names.fromString("arraycopy"),
new MethodType(List.<Type>of(syms.objectType,
syms.intType,
syms.objectType,
syms.intType,
syms.intType),
syms.voidType,
List.<Type>nil(),
syms.methodClass),
syms.systemType.tsym);
}
JCStatement copy =
make.Exec(make.App(make.Select(make.Ident(syms.systemType.tsym),
systemArraycopyMethod),
List.of(make.Ident(valuesVar), make.Literal(0),
make.Ident(resultVar), make.Literal(0),
make.Select(make.Ident(valuesVar), syms.lengthVar))));
// template: return $result;
JCStatement ret = make.Return(make.Ident(resultVar));
valuesBody = List.<JCStatement>of(decl, copy, ret);
}
JCMethodDecl valuesDef =
make.MethodDef((MethodSymbol)valuesSym,
make.Block(0, List.<JCStatement>nil()
.prepend(make.Return(valuesResult))));
make.MethodDef((MethodSymbol)valuesSym, make.Block(0, valuesBody));
enumDefs.append(valuesDef);
if (debugLower)
System.err.println(tree.sym + ".valuesDef = " + valuesDef);
/** The template for the following code is:
*
* public static E valueOf(String name) {
@ -2155,6 +2203,17 @@ public class Lower extends TreeTranslator {
addEnumCompatibleMembers(tree);
}
}
// where
private MethodSymbol systemArraycopyMethod;
private boolean useClone() {
try {
Scope.Entry e = syms.objectType.tsym.members().lookup(names.clone);
return (e.sym != null);
}
catch (CompletionFailure e) {
return false;
}
}
/** Translate an enumeration constant and its initializer. */
private void visitEnumConstantDef(JCVariableDecl var, int ordinal) {

View File

@ -1,13 +1,36 @@
/**
* @test /nodynamiccopyright/
* @bug 5045412
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java
/*
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test /nodynamiccopyright/
* @bug 5045412
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java
* @test
* @bug 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java
*/
/**
* @test
* @bug 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java
*/
class Bar implements java.io.Serializable { }

View File

@ -23,14 +23,14 @@
/**
* @test
* @bug 5045412
* @bug 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java
*/
/**
* @test
* @bug 5045412
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java
* @bug 5045412 6627366
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java
*/
class Foo { }

View File

@ -1,2 +0,0 @@
Bar.java:13:29: compiler.err.cant.resolve.location: kindname.class, Serializable, , , kindname.package, java.io
1 error

View File

@ -0,0 +1,133 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6627362
* @summary javac generates code that uses array.clone,
* which is not available on JavaCard
*/
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
public class T6627362 {
static String testSrc = System.getProperty("test.src", ".");
public static void main(String... args) throws Exception {
new T6627362().run();
}
public void run() throws Exception {
testStandard();
testNoClone();
if (errors > 0)
throw new Error(errors + " test cases failed");
}
void testStandard() throws Exception {
// compile and disassemble E.java, check for reference to Object.clone()
File x = new File(testSrc, "x");
String[] jcArgs = { "-d", ".",
new File(x, "E.java").getPath() };
compile(jcArgs);
String[] jpArgs = { "-classpath", ".", "-c", "E" };
StringWriter sw = new StringWriter();
javap(new PrintWriter(sw, true), jpArgs);
check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;");
callValues();
}
void testNoClone() throws Exception {
// compile and disassemble E.java, using modified Object.java,
// check for reference to System.arraycopy
File x = new File(testSrc, "x");
String[] jcArgs = { "-d", ".",
new File(x, "E.java").getPath(),
new File(x, "Object.java").getPath()};
compile(jcArgs);
String[] jpArgs = { "-classpath", ".", "-c", "E" };
StringWriter sw = new StringWriter();
javap(new PrintWriter(sw, true), jpArgs);
check(sw.toString(), "//Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V");
callValues();
}
void compile(String... args) {
int rc = com.sun.tools.javac.Main.compile(args);
if (rc != 0)
throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc);
}
void javap(PrintWriter out, String... args) throws Exception {
// for now, we have to exec javap
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javap = new File(new File(javaHome, "bin"), "javap");
String[] cmd = new String[args.length + 1];
cmd[0] = javap.getPath();
System.arraycopy(args, 0, cmd, 1, args.length);
Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
p.getOutputStream().close();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = in.readLine()) != null)
out.println(line);
int rc = p.waitFor();
if (rc != 0)
throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc);
}
void check(String s, String require) {
if (s.indexOf(require) == -1) {
System.err.println("Can't find " + require);
errors++;
}
}
void callValues() {
try {
File dot = new File(System.getProperty("user.dir"));
ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() });
Class<?> e_class = cl.loadClass("E");
Method m = e_class.getMethod("values", new Class[] { });
//System.err.println(m);
Object o = m.invoke(null, (Object[]) null);
List<Object> v = Arrays.asList((Object[]) o);
if (!v.toString().equals("[a, b, c]"))
throw new Error("unexpected result for E.values(): " + v);
} catch (Exception e) {
throw new Error(e);
}
}
int errors;
}

View File

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

View File

@ -0,0 +1,30 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
/*
* Object, without clone()
*/
public class Object {
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Boolean
{
public static Boolean valueOf(boolean v) {
return new Boolean(v);
}
public Boolean(boolean v) {
value = v;
}
public boolean booleanValue() {
return value;
}
private boolean value;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Byte
{
public static Byte valueOf(byte v) {
return new Byte(v);
}
public Byte(byte v) {
value = v;
}
public byte byteValue() {
return value;
}
private byte value;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Character
{
public static Character valueOf(char v) {
return new Character(v);
}
public Character(char v) {
value = v;
}
public char characterValue() {
return value;
}
private char value;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public interface Cloneable {
}

View File

@ -0,0 +1,18 @@
package java.lang;
public class Double extends Number
{
public static Double valueOf(double v) {
return new Double(v);
}
public Double(double v) {
value = v;
}
public double doubleValue() {
return value;
}
private double value;
}

View File

@ -0,0 +1,18 @@
package java.lang;
public class Float extends Number
{
public static Float valueOf(float v) {
return new Float(v);
}
public Float(float v) {
value = v;
}
public float floatValue() {
return value;
}
private float value;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Integer extends Number
{
public static Integer valueOf(int v) {
return new Integer(v);
}
public Integer(int v) {
value = v;
}
public int integerValue() {
return value;
}
private int value;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Long extends Number
{
public static Long valueOf(long v) {
return new Long(v);
}
public Long(long v) {
value = v;
}
public long longValue() {
return value;
}
private long value;
}

View File

@ -0,0 +1,122 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6627364 6627366
* @summary Synthesize important classes if they are missing from the (boot)classpath
*/
import java.io.*;
import java.util.*;
public class Main
{
File testSrc = new File(System.getProperty("test.src"));
public static void main(String[] args) throws Exception {
new Main().run();
}
public void run() throws Exception {
// compile with standard bootclasspath
compile(true, "Test.java");
// compile with various missing system classes
List<String> base_files = Arrays.asList(
"Boolean.java",
"Byte.java",
"Character.java",
"Integer.java",
"Long.java",
"Number.java",
"Object.java",
"Short.java",
"Void.java"
);
List<String> extra_files = Arrays.asList(
"Double.java",
"Float.java",
"Cloneable.java",
"Serializable.java"
);
List<String> files = new ArrayList<String>();
files.addAll(base_files);
files.add("Test.java");
compile(false, files);
for (String f: extra_files) {
files = new ArrayList<String>();
files.addAll(base_files);
files.addAll(extra_files);
files.remove(f);
files.add("Test.java");
compile(false, files);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void compile(boolean stdBootClassPath, String... files) {
compile(stdBootClassPath, Arrays.asList(files));
}
void compile(boolean stdBootClassPath, List<String> files) {
File empty = new File("empty");
empty.mkdirs();
List<String> args = new ArrayList<String>();
args.add("-classpath");
args.add("empty");
if (!stdBootClassPath) {
args.add("-bootclasspath");
args.add("empty");
}
args.add("-d");
args.add(".");
for (String f: files)
args.add(new File(testSrc, f).getPath());
System.out.println("Compile: " + args);
StringWriter out = new StringWriter();
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]),
new PrintWriter(out));
System.out.println(out.toString());
System.out.println("result: " + rc);
System.out.println();
if (rc != 0)
errors++;
}
private int errors;
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Number
{
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Object
{
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.io;
public interface Serializable {
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Short extends Number
{
public static Short valueOf(short v) {
return new Short(v);
}
public Short(short v) {
value = v;
}
public short shortValue() {
return value;
}
private short value;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
// This code (indirectly) requires the presence of
// Cloneable and Serializable (supertypes for Java arrays)
// Double and Float (for boxing/unboxing)
public class Test
{
Object f(boolean b, int[] array) {
return b ? array : 2;
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package java.lang;
public class Void
{
}