changeset 9:04a710d02dce jdk6-b04

6755905: Changes for openjdk6 build 04 6569789: Compiler test lang/TYPE/type153/type15304/type15304.html fails since jdk7 b05 6638501: Regression with Javac in JDK6 U4 b03? Summary: Final b04 state (as defined by the source bundle) Reviewed-by: darcy
author ohair
date Fri, 30 Jan 2009 16:24:58 -0800
parents f2c4205f2569
children c2ef54a6fce3
files src/share/classes/com/sun/tools/javac/comp/Infer.java src/share/classes/com/sun/tools/javac/util/Paths.java test/tools/javac/Paths/6638501/HelloLib/test/HelloImpl.java test/tools/javac/Paths/6638501/JarFromManifestFailure.java test/tools/javac/Paths/6638501/WsCompileExample.java test/tools/javac/Paths/6638501/test/SayHello.java test/tools/javac/Paths/6638501/test1/SayHelloToo.java test/tools/javac/generics/inference/6569789/T6569789.java
diffstat 8 files changed, 406 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Jan 30 16:20:54 2009 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Jan 30 16:24:58 2009 -0800
@@ -157,6 +157,19 @@
 		    if (isSubClass(bs.head, that.hibounds))
 			that.inst = types.fromUnknownFun.apply(bs.head);
 		}
+                if (that.inst == null) {
+                    int classCount = 0, interfaceCount = 0;
+                    for (Type t : that.hibounds) {
+                        if (t.tag == CLASS) {
+                            if (t.isInterface())
+                                interfaceCount++;
+                            else
+                                classCount++;
+                        }
+                    }
+                    if ((that.hibounds.size() == classCount + interfaceCount) && classCount == 1)
+                        that.inst = types.makeCompoundType(that.hibounds);
+                }
 		if (that.inst == null || !types.isSubtypeUnchecked(that.inst, that.hibounds, warn))
 		    throw ambiguousNoInstanceException
 			.setMessage("no.unique.maximal.instance.exists",
--- a/src/share/classes/com/sun/tools/javac/util/Paths.java	Fri Jan 30 16:20:54 2009 -0800
+++ b/src/share/classes/com/sun/tools/javac/util/Paths.java	Fri Jan 30 16:24:58 2009 -0800
@@ -89,7 +89,7 @@
 
     private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this.
     private static Map<File, PathEntry> pathExistanceCache = new ConcurrentHashMap<File, PathEntry>();
-    private static Map<File, java.util.List<String>> manifestEntries = new ConcurrentHashMap<File, java.util.List<String>>();
+    private static Map<File, java.util.List<File>> manifestEntries = new ConcurrentHashMap<File, java.util.List<File>>();
     private static Map<File, Boolean> isDirectory = new ConcurrentHashMap<File, Boolean>();
     private static Lock lock = new ReentrantLock();
     
@@ -369,13 +369,13 @@
 	// filenames, but if we do, we should redo all path-related code.
 	private void addJarClassPath(File jarFile, boolean warn) {
 	    try {
-                java.util.List<String> manifestsList = manifestEntries.get(jarFile);
+                java.util.List<File> manifestsList = manifestEntries.get(jarFile);
                 if (!NON_BATCH_MODE) {
                     lock.lock();
                     try {
                         if (manifestsList != null) {
-                            for (String entr : manifestsList) {
-                                addFile(new File(entr), warn);
+                            for (File entr : manifestsList) {
+                                addFile(entr, warn);
                             }
                             return;
                         }
@@ -386,7 +386,7 @@
                 }
                 
                 if (!NON_BATCH_MODE) {
-                    manifestsList = new ArrayList<String>();
+                    manifestsList = new ArrayList<File>();
                     manifestEntries.put(jarFile, manifestsList);
                 }
 
@@ -412,7 +412,7 @@
                         if (!NON_BATCH_MODE) {
                             lock.lock();
                             try {
-                                manifestsList.add(elt);
+                                manifestsList.add(f);
                             }
                             finally {
                                 lock.unlock();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Paths/6638501/HelloLib/test/HelloImpl.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,9 @@
+package test;
+
+public class HelloImpl {
+
+ public void Hello() {
+    java.lang.System.out.println("Hello");
+ }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Paths/6638501/JarFromManifestFailure.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ */
+
+/*
+ * @test
+ * @bug 6638501 
+ * @summary REGRESSION:  Java Compiler cannot find jar files referenced by other
+ * @run main JarFromManifestFailure
+ */
+
+import java.io.*;
+import java.nio.*;
+import java.util.*;
+import java.util.jar.*;
+import javax.tools.*;
+import javax.tools.StandardJavaFileManager.*;
+
+public class JarFromManifestFailure {
+    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(testClasses, null, new File(testSrc, "HelloLib/test/HelloImpl.java"), new File(testSrc, "WsCompileExample.java"));
+        File libFile = new File(testClasses, "lib");
+        libFile.mkdir();
+        jar(new File(libFile, "HelloLib.jar"), new ArrayList(), testClasses, new File("test"));
+
+        ArrayList arList = new ArrayList();
+        arList.add(new File("HelloLib.jar"));
+        jar(new File(libFile, "JarPointer.jar"), arList, testClasses);
+
+        String [] args1 = new String[3];
+        args1[0] = "-cp";
+        args1[1] = new File(libFile, "JarPointer.jar").toString().replace('\\', '/');
+        args1[2] = new File(testSrc, "test/SayHello.java").toString().replace('\\', '/');
+        System.err.println("First compile!!!");
+        if (com.sun.tools.javac.Main.compile(args1) != 0) {
+            throw new AssertionError("Failure in first compile!");
+        }
+
+        System.err.println("Second compile!!!");
+        
+        args1 = new String[3];
+        args1[0] = "-cp";
+        args1[1] = new File(libFile, "JarPointer.jar").toString().replace('\\', '/');
+        args1[2] = new File(testSrc, "test1/SayHelloToo.java").toString().replace('\\', '/');
+        if (com.sun.tools.javac.Main.compile(args1) != 0) {
+            throw new AssertionError("Failure in second compile!");
+        }
+    }
+    
+    static void compile(File classOutDir, Iterable<File> classPath, File... files) {
+        System.err.println("compile...");
+        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        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, " "));
+        }
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(jar));
+        JarOutputStream j = new JarOutputStream(out, m);
+        add(j, base, files);
+        j.close();
+    }
+    
+    static void add(JarOutputStream j, File base, File... files) throws IOException {
+        if (files == null)
+            return;
+        
+        for (File f: files) 
+            add(j, base, f);
+    }
+    
+    static void add(JarOutputStream j, File base, File file) throws IOException {
+        File f = new File(base, file.getPath());
+        if (f.isDirectory()) {
+            JarEntry e = new JarEntry(new String(file.getPath() + File.separator).replace('\\', '/'));
+            e.setSize(file.length());            
+            j.putNextEntry(e);
+            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().replace('\\', '/'));
+            e.setSize(f.length());
+            j.putNextEntry(e);
+            j.write(read(f));
+            j.closeEntry();
+        }
+        
+    }
+    
+    static byte[] read(File f) throws IOException {
+        byte[] buf = new byte[(int) f.length()];
+        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+        int offset = 0;
+        while (offset < buf.length) {
+            int n = in.read(buf, offset, buf.length - offset);
+            if (n < 0)
+                throw new EOFException();
+            offset += n;
+        } 
+        return buf;
+    }
+    
+    static <T> Iterable<T> iterable(T single) {
+        return Collections.singleton(single);
+    }
+    
+    static <T> String join(Iterable<T> iter, String sep) {
+        StringBuilder p = new StringBuilder();
+        for (T t: iter) {
+            if (p.length() > 0) 
+                p.append(' ');
+            p.append(t);
+        }
+        return p.toString();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Paths/6638501/WsCompileExample.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,167 @@
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+//for CompilerHelper
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+
+
+public class WsCompileExample {
+    File destDir;
+    File srcDir;
+    protected boolean compilerDebug = false;
+    protected boolean compilerOptimize = false;
+    protected String userClasspath = null;
+
+    public static void main(String[] args) {
+        new WsCompileExample().do_main(args);
+    }
+
+    public void do_main(String[] args) {
+        if(!args[0].equals("-s")) {
+            throw new RuntimeException("specify -s for src");
+        }
+
+        //run it once
+        srcDir =  new File(args[1]);
+        if(!args[2].equals("-d")) {
+            throw new RuntimeException("specify -d for dest");
+        }
+        destDir =  new File(args[3]);
+        if(!destDir.exists())
+            destDir.mkdirs();
+        System.out.println("----test compile 1-----");
+        compileGeneratedClasses();
+
+        //run it twice
+         srcDir = new File(args[1]+"1");
+         destDir =  new File(args[3]+"1");
+        if(!destDir.exists())
+            destDir.mkdirs();
+        System.out.println("----test compile 2-----");
+        compileGeneratedClasses();
+
+    }
+    protected void compileGeneratedClasses() {
+        List sourceFiles = new ArrayList();
+
+        for (File f: srcDir.listFiles()) {
+            if (f.getName().endsWith(".java")) {
+                sourceFiles.add(f.getAbsolutePath());
+            }
+        }
+
+        if (sourceFiles.size() > 0) {
+				String classDir = destDir.getAbsolutePath();
+            String classpathString = createClasspathString();
+            System.out.println("classpathString: " + classpathString);
+
+				String[] args = new String[4 + (compilerDebug == true ? 1 : 0) +
+                (compilerOptimize == true ? 1 : 0) +
+                sourceFiles.size()];
+            args[0] = "-d";
+            args[1] = classDir;
+            args[2] = "-classpath";
+            args[3] = classpathString;
+//				args[4]="-DnonBatchMode";
+            int baseIndex = 4;
+            if (compilerDebug) {
+                args[baseIndex++] = "-g";
+            }
+            if (compilerOptimize) {
+                args[baseIndex++] = "-O";
+            }
+            for (int i = 0; i < sourceFiles.size(); ++i) {
+                args[baseIndex + i] = (String)sourceFiles.get(i);
+            }
+
+            // ByteArrayOutputStream javacOutput = new ByteArrayOutputStream();
+            JavaCompilerHelper compilerHelper = new JavaCompilerHelper(System.out);
+            boolean result = compilerHelper.compile(args);
+            if (!result) {
+                System.out.println("wscompile.compilation Failed");
+            }
+        }
+    }
+
+    protected String createClasspathString() {
+        if (userClasspath == null) {
+            userClasspath = "";
+        }
+			  String jcp = userClasspath + File.pathSeparator + System.getProperty("java.class.path");
+		  return jcp;
+    }
+}
+///////////////////////////////////////////////////////////////////
+class JavaCompilerHelper {
+    public JavaCompilerHelper(OutputStream out) {
+		this.out = out;
+	}
+
+	public boolean compile(String[] args) {
+		return internalCompile(args);
+	}
+
+	protected boolean internalCompile(String[] args) {
+
+		System.out.println("Args: ");
+		for(String arg : args){
+			System.out.print(arg+" ");
+		}
+        System.out.println();
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		Class comSunToolsJavacMainClass = null;
+		try {
+			/* try to use the new compiler */
+			comSunToolsJavacMainClass =
+				cl.loadClass("com.sun.tools.javac.Main");
+			try {
+				Method compileMethod =
+					comSunToolsJavacMainClass.getMethod(
+						"compile",
+						compile141MethodSignature);
+				try {
+					Object result =
+						compileMethod.invoke(
+							null,
+							new Object[] { args, new PrintWriter(out)});
+					if (!(result instanceof Integer)) {
+						return false;
+					}
+					return ((Integer) result).intValue() == 0;
+				} catch (IllegalAccessException e3) {
+					return false;
+				} catch (IllegalArgumentException e3) {
+					return false;
+				} catch (InvocationTargetException e3) {
+					return false;
+				}
+			} catch (NoSuchMethodException e2) {
+              System.out.println("ERROR: Compile failed with error:" + e2.toString() );
+			}
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+			return false;
+		} catch (SecurityException e) {
+			return false;
+		}
+                return true;
+	}
+
+	protected String getGenericErrorMessage() {return "javacompiler.error";	}
+	protected void run() {	}
+	protected boolean parseArguments(String[] args) {return false;}
+	protected OutputStream out;
+
+	protected static final Class[] compile141MethodSignature;
+	static
+	{
+		compile141MethodSignature = new Class[2];
+		compile141MethodSignature[0] = (new String[0]).getClass();
+		compile141MethodSignature[1] = PrintWriter.class;
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Paths/6638501/test/SayHello.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,9 @@
+import test.HelloImpl;
+
+public class SayHello extends HelloImpl {
+  public static void main(String... args) {
+    new SayHello().Hello();
+}
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Paths/6638501/test1/SayHelloToo.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,9 @@
+import test.HelloImpl;
+
+public class SayHelloToo extends HelloImpl {
+  public static void main(String... args) {
+    new SayHelloToo().Hello();
+}
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/inference/6569789/T6569789.java	Fri Jan 30 16:24:58 2009 -0800
@@ -0,0 +1,44 @@
+/*
+ * 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
+ * @bug     6569789
+ * @summary Compiler test lang/TYPE/type153/type15304/type15304.html fails since jdk7 b05
+ * @compile T6569789.java
+ */
+
+class C {}
+interface I {}
+interface I1 {}
+interface I2 {}
+class CT extends C implements I, I1, I2 {}
+
+public class T6569789 {
+    public static void m() {
+        CT ct = new CT();
+        testMethod(ct);
+    }
+
+    static <W extends C & I & I1 & I2, T extends W> void testMethod(T t) {}
+}